This is a migrated thread and some comments may be shown as answers.

Android Webpack- .RuntimeException: Unable to instantiate activity

3 Answers 362 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anurag
Top achievements
Rank 1
Anurag asked on 04 Oct 2017, 04:35 PM

Hi
After a lot of efforts I finally managed to get my project to build with webpack in both android and IOS - npm run build-ios-bundle and npm run build-android-bundle both work and I am able to build the project successfully.
However when i try to run the project in Android i get the following error:

 

<p>System.err: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.nativescript.qbank/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
System.err: Error: com.tns.NativeScriptException: Failed to find module: "./tns_modules/tns-core-modules/ui/frame/activity.js", relative to: app//
System.err:     com.tns.Module.resolvePathHelper(Module.java:146)
System.err:     com.tns.Module.resolvePath(Module.java:55)
System.err:     com.tns.Runtime.runModule(Native Method)
System.err:     com.tns.Runtime.runModule(Runtime.java:530)
System.err:     com.tns.Runtime.createJSInstance(Runtime.java:624)
System.err:     com.tns.Runtime.initInstance(Runtime.java:606)
System.err:     com.tns.NativeScriptActivity.<init>(NativeScriptActivity.java:7)
System.err:     java.lang.Class.newInstance(Native Method)
System.err:     android.app.Instrumentation.newActivity(Instrumentation.java:1068)
System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
System.err:     android.app.ActivityThread.access$900(ActivityThread.java:153)
System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     android.os.Looper.loop(Looper.java:148)
System.err:     android.app.ActivityThread.main(ActivityThread.java:5438)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
System.err: File: "<unknown>, line: 1, column: 265
System.err: StackTrace:
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
System.err:     at android.app.ActivityThread.access$900(ActivityThread.java:153)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:148)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:5438)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
System.err: Caused by: com.tns.NativeScriptException:
System.err: Error: com.tns.NativeScriptException: Failed to find module: "./tns_modules/tns-core-modules/ui/frame/activity.js", relative to: app//
System.err:     com.tns.Module.resolvePathHelper(Module.java:146)
System.err:     com.tns.Module.resolvePath(Module.java:55)
System.err:     com.tns.Runtime.runModule(Native Method)
System.err:     com.tns.Runtime.runModule(Runtime.java:530)
System.err:     com.tns.Runtime.createJSInstance(Runtime.java:624)
System.err:     com.tns.Runtime.initInstance(Runtime.java:606)
System.err:     com.tns.NativeScriptActivity.<init>(NativeScriptActivity.java:7)
System.err:     java.lang.Class.newInstance(Native Method)
System.err:     android.app.Instrumentation.newActivity(Instrumentation.java:1068)
System.err:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
System.err:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
System.err:     android.app.ActivityThread.access$900(ActivityThread.java:153)
System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     android.os.Looper.loop(Looper.java:148)
System.err:     android.app.ActivityThread.main(ActivityThread.java:5438)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
System.err: File: "<unknown>, line: 1, column: 265
System.err: StackTrace:
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err:     at com.tns.Runtime.runModule(Native Method)
System.err:     at com.tns.Runtime.runModule(Runtime.java:530)
System.err:     at com.tns.Runtime.createJSInstance(Runtime.java:624)
System.err:     at com.tns.Runtime.initInstance(Runtime.java:606)
System.err:     at com.tns.NativeScriptActivity.<init>(NativeScriptActivity.java:7)
System.err:     at java.lang.Class.newInstance(Native Method)
System.err:     at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
System.err:     ... 9 more </p><p></p>

Please let me know what I can do or if you need more information.
On IOS the project runs but the styles are not applied and I get a different error logged here
Project uses the latest tns version 3.2.0.
Thanks

Anurag

3 Answers, 1 is accepted

Sort by
0
Nikolay Tsonev
Telerik team
answered on 05 Oct 2017, 10:05 AM
Hi, Anurag,

Thank you for reporting this info.

Could you provide info, if you are extending the Android activity in your NativeScript Angular application while following the instruction here? In case the activity is extended, some extra configuration are needed in the webpack.config.js file.

If this is the case, you should add MainActivity: './activity', 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: './activity',
 
    // Entry for stylesheet with global application styles
    [mainSheet]: `./${mainSheet}`,
};

Keep in mind that after you make those changes, you should remove node_modules and platforms folder before rebuilding the app. I am attaching also sample project, where this case is demonstrated.

I am attaching also sample project, where this case is demonstrated. 

Hope this helps
Regards,
nikolay.tsonev
Progress Telerik
Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
0
Anurag
Top achievements
Rank 1
answered on 06 Oct 2017, 07:54 AM

Hi Nikolay

Thanks for the suggestion, I checked my project and I am not extending the android activity anywhere in my app. I looked at the project you had shared and in comparison to that I have one difference - as mentioned in in an earlier request, to get the project to build correctly I have changed the paths in the tsconfig.aot.json file as follows:

I have deleted this 

{
"extends": "./tsconfig",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"application": ["node_modules/tns-core-modules/application"],
"application-settings": ["node_modules/tns-core-modules/application-settings"],
"camera": ["node_modules/tns-core-modules/camera"],
"color": ["node_modules/tns-core-modules/color"],
"connectivity": ["node_modules/tns-core-modules/connectivity"],
"console": ["node_modules/tns-core-modules/console"],
"data/*": ["node_modules/tns-core-modules/data/*"],
"fetch": ["node_modules/tns-core-modules/fetch"],
"file-system": ["node_modules/tns-core-modules/file-system"],
"fps-meter": ["node_modules/tns-core-modules/fps-meter"],
"globals": ["node_modules/tns-core-modules/globals"],
"http": ["node_modules/tns-core-modules/http"],
"image-asset": ["node_modules/tns-core-modules/image-asset"],
"image-source": ["node_modules/tns-core-modules/image-source"],
"location": ["node_modules/tns-core-modules/location"],
"platform": ["node_modules/tns-core-modules/platform"],
"text": ["node_modules/tns-core-modules/text"],
"timer": ["node_modules/tns-core-modules/timer"],
"trace": ["node_modules/tns-core-modules/trace"],
"ui/*": ["node_modules/tns-core-modules/ui/*"],
"utils/*": ["node_modules/tns-core-modules/utils/*"],
"xhr": ["node_modules/tns-core-modules/xhr"],
"xml": ["node_modules/tns-core-modules/xml"]
},

 

and replaced it with this

{
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}

As mentioned the webpack project builds and runs fine for ios. For android however, even though the project builds with webpack at runtime I get this error. Let me know if I can provide more information.

Thanks

Anurag

 

 

 

 

 

 

0
Nikolay Tsonev
Telerik team
answered on 06 Oct 2017, 01:31 PM
Hi Anurag,

In our further investigation with our developer team, we found that the change in the tsconfig.aot.jso, should not affect the starting the application in Android. 

Regarding ticket 1131429, you mentioned there that you are looking for a way to recreate the error in a sample project, which could be used to investigate the issue on our side, Did you manage to create such an app? 

It would help if you provide some more info about your environment(node, npm versions, OS version of the machine) and more info about the Android device r emulator, which you used for testing. Also send us the latest veriosn of your project package.json file.

In the meantime, Something that you could try is the below-described steps, which will add the newest versions of the configurations for you.

1. Edit the package.json file as it is shown below
//package.json
// ...
"scripts": {
    "update-ns-webpack": "update-ns-webpack"
    // ...
}
2. Remove the node modules and the package-lock.json (if you are using npm5+):
rm -rf node_modules package-lock.json

3. Install the new modules:
npm i

4. For updating the webpack configuration, just delete these files:
rm webpack.*.js app/vendor*
5. And then run
npm i -D nativescript-dev-webpack



Regards,
nikolay.tsonev
Progress Telerik
Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
Tags
General Discussion
Asked by
Anurag
Top achievements
Rank 1
Answers by
Nikolay Tsonev
Telerik team
Anurag
Top achievements
Rank 1
Share this question
or