Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27135] Android: Broken incremental builds when using encrypted assets or referencing JS from HTML

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2019-11-05T20:22:14.000+0000
Affected Version/sRelease 8.1.0
Fix Version/sRelease 8.1.0
ComponentsAndroid
Labelsandroid, build, engSchedule, regression
ReporterGary Mathews
AssigneeJoshua Quick
Created2019-06-05T22:53:53.000+0000
Updated2019-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)

Comments

  1. Joshua Quick 2019-06-06

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10945
  2. Joshua Quick 2019-06-07

    ^ 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...
       [ERROR] Failed to compile Java source files:
       [ERROR]   
       [ERROR] /Users/jquick2/Documents/Appcelerator_Studio_Workspace/ClassicAppTest/build/android/gen/com/appcelerator/testing/AssetCryptImpl.java:58: error: cannot find symbol
       [ERROR]         	return assets.keySet();
       [ERROR]         	       ^
       [ERROR]   symbol:   variable assets
       [ERROR]   location: class AssetCryptImpl
       [ERROR] /Users/jquick2/Documents/Appcelerator_Studio_Workspace/ClassicAppTest/build/android/gen/com/appcelerator/testing/AssetCryptImpl.java:74: error: cannot find symbol
       [ERROR]         	Range range = assets.get(path);
       [ERROR]         	              ^
       [ERROR]   symbol:   variable assets
       [ERROR]   location: class AssetCryptImpl
       [ERROR] /Users/jquick2/Documents/Appcelerator_Studio_Workspace/ClassicAppTest/build/android/gen/com/appcelerator/testing/AssetCryptImpl.java:79: error: cannot find symbol
       [ERROR]         	return filterDataInRange(assetsBytes, range.offset, range.length);
       [ERROR]         	                         ^
       [ERROR]   symbol:   variable assetsBytes
       [ERROR]   location: class AssetCryptImpl
       [ERROR] Note: /Users/jquick2/Documents/Appcelerator_Studio_Workspace/ClassicAppTest/build/android/gen/com/appcelerator/testing/AssetCryptImpl.java uses unchecked or unsafe operations.
       [ERROR] Note: Recompile with -Xlint:unchecked for details.
       [ERROR] 3 errors
       
    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.
       [ERROR] TiAssetHelper: Error while reading asset "Resources/ti.main.js":
       [ERROR] TiAssetHelper: java.io.FileNotFoundException: Resources/ti.main.js
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.nativeOpenAsset(Native Method)
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.open(AssetManager.java:744)
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.open(AssetManager.java:721)
       [ERROR] TiAssetHelper: 	at org.appcelerator.kroll.util.KrollAssetHelper.readAsset(KrollAssetHelper.java:165)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiLaunchActivity.loadScript(TiLaunchActivity.java:99)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiRootActivity.loadScript(TiRootActivity.java:466)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiLaunchActivity.onResume(TiLaunchActivity.java:183)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiRootActivity.onResume(TiRootActivity.java:485)
       [ERROR] TiAssetHelper: 	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412)
       [ERROR] TiAssetHelper: 	at android.app.Activity.performResume(Activity.java:7300)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3777)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3817)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
       [ERROR] TiAssetHelper: 	at android.os.Handler.dispatchMessage(Handler.java:106)
       [ERROR] TiAssetHelper: 	at android.os.Looper.loop(Looper.java:193)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.main(ActivityThread.java:6680)
       [ERROR] TiAssetHelper: 	at java.lang.reflect.Method.invoke(Native Method)
       [ERROR] TiAssetHelper: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       [ERROR] TiAssetHelper: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
       [ERROR] TiAssetHelper: Error while reading asset "Resources/ti.main.js":
       [ERROR] TiAssetHelper: java.io.FileNotFoundException: Resources/ti.main.js
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.nativeOpenAsset(Native Method)
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.open(AssetManager.java:744)
       [ERROR] TiAssetHelper: 	at android.content.res.AssetManager.open(AssetManager.java:721)
       [ERROR] TiAssetHelper: 	at org.appcelerator.kroll.util.KrollAssetHelper.readAsset(KrollAssetHelper.java:165)
       [ERROR] TiAssetHelper: 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
       [ERROR] TiAssetHelper: 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:162)
       [ERROR] TiAssetHelper: 	at org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:207)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiLaunchActivity.loadScript(TiLaunchActivity.java:99)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiRootActivity.loadScript(TiRootActivity.java:466)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiLaunchActivity.onResume(TiLaunchActivity.java:183)
       [ERROR] TiAssetHelper: 	at org.appcelerator.titanium.TiRootActivity.onResume(TiRootActivity.java:485)
       [ERROR] TiAssetHelper: 	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412)
       [ERROR] TiAssetHelper: 	at android.app.Activity.performResume(Activity.java:7300)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3777)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3817)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
       [ERROR] TiAssetHelper: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
       [ERROR] TiAssetHelper: 	at android.os.Handler.dispatchMessage(Handler.java:106)
       [ERROR] TiAssetHelper: 	at android.os.Looper.loop(Looper.java:193)
       [ERROR] TiAssetHelper: 	at android.app.ActivityThread.main(ActivityThread.java:6680)
       [ERROR] TiAssetHelper: 	at java.lang.reflect.Method.invoke(Native Method)
       [ERROR] TiAssetHelper: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       [ERROR] TiAssetHelper: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
       
  3. Joshua Quick 2019-06-08

    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.
  4. Joshua Quick 2019-06-11

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10945 PR (8.1.x): https://github.com/appcelerator/titanium_mobile/pull/10958
  5. Keerthi Mahalingam 2019-06-11

    FR Passed .Waiting on Jenkins.
  6. Keerthi Mahalingam 2019-06-12

    PR merged
  7. Keerthi Mahalingam 2019-06-13

    Verified the Fix on SDK 8.2.0.v20190612155743 and 8.1.0.v20190612160220.Works as expected. No errors displayed on launching app. Closing.
       Name                        = Mac OS X
         Version                     = 10.13.6
         Architecture                = 64bit
         # CPUs                      = 8
         Memory                      = 17179869184
       Node.js
         Node.js Version             = 10.13.0
         npm Version                 = 6.4.1
       Titanium CLI
         CLI Version                 = 5.1.1
       Titanium SDK
         SDK Version                 = sdk 8.1.0.v20190612160220 and 8.2.0.v20190612155743
       Device =Nexus android 5,Oneplus 5t android 9
       

JSON Source