Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Bundle not working on Android 7.1 #91

Closed
abhayastudios opened this issue Feb 28, 2017 · 8 comments
Closed

Bundle not working on Android 7.1 #91

abhayastudios opened this issue Feb 28, 2017 · 8 comments

Comments

@abhayastudios
Copy link

abhayastudios commented Feb 28, 2017

I was able to successfully bundle with v0.3.5 and test on an older Android 5 device & iOS simulator.

However, after uploading the package as alpha to the Android Play Store, a tester reported that the app crashed on Android 7.1 (see stack below).

I checked and my app/vendor-platform.android.ts is exactly like the template in the plugin.

Any advice?

java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: 
Error calling module function 
Error: com.tns.NativeScriptException: Failed to find module: "ui/frame/activity", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:154)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:15)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6119)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
File: "<unknown>, line: 1, column: 265
StackTrace: 
  Frame: function:'require', file:'', line: 1, column: 266
  Frame: function:'', file:'file:///data/data/org.nativescript.testjoni/files/app/tns-java-classes.js', line: 1, column: 61
  Frame: function:'require', file:'', line: 1, column: 266
Error: com.tns.NativeScriptException: Failed to find module: "ui/frame/activity", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:154)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:15)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6119)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
File: "<unknown>, line: 1, column: 265
StackTrace: 
  Frame: function:'require', file:'', line: 1, column: 266
  Frame: function:'', file:'file:///data/data/org.nativescript.testjoni/files/app/tns-java-classes.js', line: 1, column: 61
  Frame: function:'require', file:'', line: 1, column: 266
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
  at android.app.ActivityThread.-wrap2(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6119)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: com.tns.NativeScriptException: 
Error calling module function 
Error: com.tns.NativeScriptException: Failed to find module: "ui/frame/activity", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:154)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:15)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6119)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
File: "<unknown>, line: 1, column: 265
StackTrace: 
  Frame: function:'require', file:'', line: 1, column: 266
  Frame: function:'', file:'file:///data/data/org.nativescript.testjoni/files/app/tns-java-classes.js', line: 1, column: 61
  Frame: function:'require', file:'', line: 1, column: 266
Error: com.tns.NativeScriptException: Failed to find module: "ui/frame/activity", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:154)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:15)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6119)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
File: "<unknown>, line: 1, column: 265
StackTrace: 
  Frame: function:'require', file:'', line: 1, column: 266
  Frame: function:'', file:'file:///data/data/org.nativescript.testjoni/files/app/tns-java-classes.js', line: 1, column: 61
  Frame: function:'require', file:'', line: 1, column: 266
  at com.tns.Runtime.runModule(Native Method)
  at com.tns.Runtime.runModule(Runtime.java:580)
  at com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:154)
  at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:15)
  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
  ... 8 more
@sis0k0
Copy link
Contributor

sis0k0 commented Feb 28, 2017

Hi @abhayastudios,

I couldn't reproduce that error with any of our sample apps. I see from the stack trace that the error happened in a file named tns-java-classes.ts. If you have such file in your app, can you please share it?

@abhayastudios
Copy link
Author

abhayastudios commented Mar 1, 2017

@sis0k0 I don't have such a file. Actually I thought it was part of this plugin. When I try to find it in my project dir I don't get anything (so doesn't seem to be part of the plugins either). I even opened the APK and tried to find anything related.

Actually I do think it is related to this project, see for example #7. I see for example that index.js still contains a reference to it.

@abhayastudios
Copy link
Author

After searching a little more it seems it is originating from the dev dependency nativescript-dev-android-snapshot that is included in the NativeScript 2.5.0 project template.

node_modules/nativescript-dev-android-snapshot/hooks/after-prepare-hook.js:54-64

function prepareSnapshotPluginFiles(pluginDirectory, platformAppDirectory) {
    shelljs.cp(path.join(pluginDirectory, "platforms/android-snapshot-files/_embedded_script_.js"), platformAppDirectory);
    shelljs.cp(path.join(pluginDirectory, "platforms/android-snapshot-files/tns-java-classes.js"), platformAppDirectory);

    shelljs.rm("-rf", path.join(platformAppDirectory, "../snapshots"));
    var snapshotBlobs = path.join(pluginDirectory, "platforms/android-snapshot-files/snapshots")
    if (shelljs.test("-e", snapshotBlobs)) {
        shelljs.cp("-r", snapshotBlobs, path.join(platformAppDirectory, ".."));
        addSnapshotKeyInPackageJSON(path.join(platformAppDirectory, "package.json"));
    }
}

@sis0k0
Copy link
Contributor

sis0k0 commented Mar 2, 2017

Oh, I'm sorry, I haven't noticed that you may be using our snapshot plugin. It provides a great way to reduce the startup time of your android app. However, snapshots are not compatible with the webpack plugin yet. So, for now you'll have to remove the snapshot plugin from your dependencies.

@abhayastudios
Copy link
Author

@sis0k0 to be completely honest I am not consciously using the snapshot plugin, it just came as a devDependency with the NativeScript 2.5.0 project template.

If I bundle like this npm run build-android-bundle -- --release shouldn't it skip the dev dependencies?

@sis0k0
Copy link
Contributor

sis0k0 commented Mar 2, 2017

Actually, it's just the opposite - the snapshot plugin is activated only when building for release (because the debugger doesn't work with snapshots). I agree this can be kinda confusing since the plugin doesn't work with webpack but its dependency comes with our project template. We'll address this problem.

Let me know if removing the plugin solves the problem on Android 7.1. I'll keep this issue open since then.

@abhayastudios
Copy link
Author

Yes that seems to have fixed the problem :)

Since the project template contains the dependency for nativescript-dev-android-snapshot, it would probably be a good idea to mention in this project's README that it needs to be deleted. WDYT?

By the way, in your experience what would result in faster startup time a build with snapshots or with webpack? The point of using webpack for me is to reduce startup time... (I dont care too much about the smaller file size).

Thanks!

@sis0k0
Copy link
Contributor

sis0k0 commented Mar 7, 2017

Hey, there! Sorry for the late reply. The startup time heavily depends on the device, the android API level and mostly - on your app. First of all, the snapshot works only for Android. Also it is applied on the code from nativescript-angular and tns-core-modules. With that being said, in my experience, snapshots provide better performance for smaller apps.

But as I said, it heavily depends on your app and it would be the best to make some measurements with both options on different devices. I'll be happy if you share your results with us!

@sis0k0 sis0k0 closed this as completed Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants