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

Missing Extented activity when using webpack bundeling #235

Closed
ahaebi opened this issue Jul 25, 2017 · 3 comments
Closed

Missing Extented activity when using webpack bundeling #235

ahaebi opened this issue Jul 25, 2017 · 3 comments

Comments

@ahaebi
Copy link

ahaebi commented Jul 25, 2017

My android app collects onKeyDown/onKeyUp events with an extented activity (based on https://docs.nativescript.org/runtimes/android/advanced-topics/extend-application-activity#extending-activity).

When starting the bundeled app (npm run ns-bundle --android --run-app) my extended Activity is not found (ClassNotFoundException):

An uncaught Exception occurred on "main" thread.
 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.nativescript.ExtentedActivityTest/org.myApp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "org.myApp.MainActivity" on path: DexPathList[[zip file "/data/app/org.nativescript.ExtentedActivityTest-1/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.ExtentedActivityTest-1/lib/arm, /data/app/org.nativescript.ExtentedActivityTest-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2853)
 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
 	at android.app.ActivityThread.-wrap14(ActivityThread.java)
 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1646)
 	at android.os.Handler.dispatchMessage(Handler.java:102)
 	at android.os.Looper.loop(Looper.java:154)
 	at android.app.ActivityThread.main(ActivityThread.java:6836)
 	at java.lang.reflect.Method.invoke(Native Method)
 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.myApp.MainActivity" on path: DexPathList[[zip file "/data/app/org.nativescript.ExtentedActivityTest-1/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.ExtentedActivityTest-1/lib/arm, /data/app/org.nativescript.ExtentedActivityTest-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
 	at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
 	at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
 	... 9 more
  • When start the standard way (tns run android) the app is running as supossed.

Environment

All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬───────────────┐
│ Component        │ Current version │ Latest version │ Information   │
│ nativescript     │ 3.1.2           │ 3.1.2          │ Up to date    │
│ tns-core-modules │ 3.1.0           │ 3.1.0          │ Up to date    │
│ tns-android      │ 3.1.1           │ 3.1.1          │ Up to date    │
│ tns-ios          │                 │ 3.1.0          │ Not installed │
└──────────────────┴─────────────────┴────────────────┴───────────────┘

Google/SO couldn't help any further

Test project

In the attachment you'll find a test project. The extended activity is located in app/MainActivity.android.ts.
ExtentedActivityTest.zip

@m-abs
Copy link

m-abs commented Jul 28, 2017

Thanks, that was an interesting problem :)

Try adding MainActivity: './MainActivity', to the entry in webpack.config.js like this:

    const entry = {
        // Discover entry module from package.json
        bundle: `./${nsWebpack.getEntryModule()}`,

        // Vendor entry with third-party libraries
        vendor: `./vendor`,

        /// HERE
        MainActivity: './MainActivity',

        // Entry for stylesheet with global application styles
        [mainSheet]: `./${mainSheet}`,
    };

@spike1292
Copy link

I have added the require to thevendor-platform.android.ts:

require("application");
if (!global["__snapshot"]) {
    /* 
    In case snapshot generation is enabled these modules will get into the bundle but will not be required/evaluated. 
    The snapshot webpack plugin will add them to the tns-java-classes.js bundle file. This way, they will be evaluated on app start as early as possible.
    */
    require("ui/frame");
    require("ui/frame/activity");
}

require("./MainActivity.android.js");

This setup worked for us 😉

@ahaebi
Copy link
Author

ahaebi commented Aug 3, 2017

Thank you, this solved the issue twice 👍 👍

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

3 participants