[TIMOB-27135] Android: Broken incremental builds when using encrypted assets or referencing JS from HTML
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-11-05T20:22:14.000+0000 |
Affected Version/s | Release 8.1.0 |
Fix Version/s | Release 8.1.0 |
Components | Android |
Labels | android, build, engSchedule, regression |
Reporter | Gary Mathews |
Assignee | Joshua Quick |
Created | 2019-06-05T22:53:53.000+0000 |
Updated | 2019-11-05T20:22:18.000+0000 |
Description
*Summary:*
The changes made by [TIMOB-27043] is causing Android build issues as of 8.1.0.
Note that this issue was never released. We've caught it before RC.
----
*Issue 1:*
Building an Android project with asset encryption enabled (which "device" and "production" builds do by default) will fail when built the 2nd time.
To reproduce, run the below command on a project twice. It'll fail on the 2nd attempt.
appc run -p android --build-only --deploy-type test
The above will typically fail on the 2nd attempt with...
[ERROR] : Failed to compile Java source files:
[ERROR] :
[ERROR] : /Users/lchoudhary/Desktop/workspaces/workspace_2019/kitchensink-v2-master/build/android/gen/com/appcelerator/kitchensink/KitchensinkApplication.java:40: error: cannot find symbol
[ERROR] : KrollAssetHelper.setAssetCrypt(new AssetCryptImpl());
[ERROR] : ^
[ERROR] : symbol: class AssetCryptImpl
[ERROR] : location: class KitchensinkApplication
[ERROR] : Note: /Users/lchoudhary/Desktop/workspaces/workspace_2019/kitchensink-v2-master/build/android/gen/com/appcelerator/kitchensink/KitchensinkApplication.java uses unchecked or unsafe operations.
[ERROR] : Note: Recompile with -Xlint:unchecked for details.
[ERROR] : 1 error
[ERROR] Application Installer abnormal process termination. Process exit value was 1
----
*Issue 2:*
A local HTML file that references a JavaScript file via the <script/>
tag will cause an immediate build failure.
Steps to reproduce:
Copy the below files to a Classic app.
Build to an Android device or emulator.
Note that the build will immediately fail.
_app.js_
var window = Ti.UI.createWindow();
window.add(Ti.UI.createWebView({
url: "my.html",
}));
window.open();
_my.html_
<!DOCTYPE html>
<html>
<head>
<script src="myHtmlScript.js"></script>
</head>
<body onload="onPageLoaded();">
This verifies that a local HTML file can access a local JS file.
</body>
</html>
_myHtmlScript.js_
function onPageLoaded() {
alert("Embedded script successfully accessed via HTML file.");
}
\\
\\
The above will cause the following build failure...
[ERROR] : TypeError: Cannot read property 'cyan' of undefined
at AndroidBuilder.copyFile (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/android/cli/commands/_build.js:2352:53)
at AndroidBuilder.next (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/android/cli/commands/_build.js:2711:16)
at /Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/async/dist/async.js:3880:24
at eachOfArrayLike (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/async/dist/async.js:1069:9)
at eachOf (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/async/dist/async.js:1117:5)
at _parallel (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/async/dist/async.js:3879:5)
at Object.parallelLimit [as parallel] (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/async/dist/async.js:3962:5)
at Object.parallel (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/node_modules/node-appc/lib/async.js:56:8)
at task.run.then (/Users/jquick2/Library/Application Support/Titanium/mobilesdk/osx/8.2.0/android/cli/commands/_build.js:2707:16)
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10945
^ The above PR doesn't fully fix the incremental "device" build. After editing a JS file and rebuilding, I sometimes get the following app build error...
And after doing another rebuild after the above happens the app will successfully build, but upon app launch on device, the app will crash on startup with the following logged error. Looking under the "build" directory "gen" folder, I can see that the "AssetCryptImpl.java" file that was generated is missing all of the encrypted JS files.
The above issue happened because the "forceRebuild" flag was set which deleted the "assets" directory that once contained the JS files, but the new incremental build system does not check for output file existence and thus proceeded to build the APK containing zero JS files. Ideally, the new [process-js-task.js](https://github.com/appcelerator/titanium_mobile/blob/master/cli/lib/tasks/process-js-task.js) code that tracks incremental build changes should also verify that the output file exists as well, which would add some overhead, but would avoid issues like this. In the meantime, a quick solution in the Android "_build.js" is to delete the "incremental" build directory when the "forceRebuild" flag is set. This way the system will start with a clean slate. I've changed the PR to do exactly this and the problem is now solved.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10945 PR (8.1.x): https://github.com/appcelerator/titanium_mobile/pull/10958
FR Passed .Waiting on Jenkins.
PR merged
Verified the Fix on SDK 8.2.0.v20190612155743 and 8.1.0.v20190612160220.Works as expected. No errors displayed on launching app. Closing.