NativeScript: [NS7] - Android error extending custom activity
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 7.0.8
- Cross-platform modules: 7.0.0
- Android Runtime: 7.0.0
- iOS Runtime: 7.0.0
- Plugin(s):
Describe the bug I’ve a custom application in AndroidManifest.xml, I’ve followed this guide but it doesn’t work: https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/extend-application-activity
If I run application I’ve this error:
09-24 16:58:29.251 11882 11882 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application com.custom.NativeScriptApplication: java.lang.ClassNotFoundException: Didn't find class "com.custom.NativeScriptApplication" on path: DexPathList[[zip file "/data/app/org.nativescript.testnsng-n9D3x_-2ywiadEyA-gCknQ==/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.testnsng-n9D3x_-2ywiadEyA-gCknQ==/lib/x86_64, /data/app/org.nativescript.testnsng-n9D3x_-2ywiadEyA-gCknQ==/base.apk!/lib/x86_64, /system/lib64]]
To Reproduce I’ve added a custom application: com.custom.NativeScriptApplication It’ defined in application.android.ts, if I leave com.tns.NativeScriptApplication everything works fine.
Sample project https://github.com/mapo80/nativescript-ns7-custom-application
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 16 (11 by maintainers)
Commits related to this issue
- Fix extending android application and activity This change fixes this issue: https://github.com/NativeScript/NativeScript/issues/8893 — committed to mapo80/NativeScript by mapo80 4 years ago
@mapo80 in your
webpack.custom.config.jsyou are settingBut these are not read from
envin the main config:Adding the entry and
appComponentsto the main config works fine as @bradmartin has tried.Perhaps we could allow passing these through
env- it should be a fairly simple change if you don’t mind opening a pr: https://github.com/NativeScript/NativeScript/tree/master/packages/webpack/templates these are the default templates - that could just use something like this:I stumbled upon a lot of issues myself trying to get this to work, but I finally got it working.
First off you’ll want to ensure that the
NativeClasstransformer plugin is configured in yourtsconfig.json. Add the following if it isn’t. This will ensure all classes that are decorated withNativeClassare added to the compilation.Make sure you decorate your activity (and application) with the
NativeClassdecorator like so.Activity
Application
If you get any error about the package already existing, make sure your
idinnativescript.config.jsonandapplication.androidare not the same.@rigor789 I’ll try to make a PR for webpack.angular.js
Thanks for your advice.
@mapo80 - https://github.com/mapo80/nativescript-ns7-custom-application/pull/1 which basically just added the application file to the main webpack.config, I’m guessing the custom config might not be finding the correct entry point. I noticed during the webpack process after first pulling a warning is printed that the file is included but it’s not being used. Which makes me think how you have the custom config setup to find that file is incorrect somehow.
@bradmartin thanks for your quick reply, that did the trick 😉
@mapo80 you repo in your link doesn’t have the activity in the webpack.config here: https://github.com/mapo80/nativescript-ns7-custom-application/blob/72b7c4afe8092f5ab9264196ef6347f0df1b6eca/webpack.config.js#L30 so I’d add it as I mentioned in my previous comment and see if that helps, I don’t use the file extension on the files as that has always caused me issues with webpack going back over a year ago.
Hey @mapo80 and @shansb-dev can you remove the
.tsfrom the activity in the webpack.config you have. I believe that might be part of the issue.extended activity
webpack.config.js
Android Manifest
I have this working with 2 different NS7 android apps.
Let me know if this is helpful or not.