NativeScript: Android app crashes on launch after upgrading to NativeScript 6.2

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: 6.2.1
  • Cross-platform modules: 6.2.1
  • Android Runtime: 6.2.0
  • iOS Runtime: 6.2.0
  • Plugin(s):
@nota/nativescript-webview-ext, 
@nstudio/nativescript-checkbox, 
nativescript-advanced-webview, 
nativescript-angular, 
nativescript-app-sync, 
nativescript-bitmap-factory, 
nativescript-camera, 
nativescript-drop-down, 
nativescript-email, 
nativescript-exit, 
nativescript-image-zoom, 
nativescript-imagepicker, 
nativescript-iqkeyboardmanager, 
nativescript-local-notifications, 
nativescript-plugin-firebase, 
nativescript-theme-core, 
nativescript-toasty, 
nativescript-ui-gauge, 
nativescript-ui-listview, 
nativescript-ui-sidedrawer, 
nativescript-windowed-modal

Describe the bug

After upgrading my NativeScript project to 6.2, our application crashes with the following error:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onStart failed
System.err: Error: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"
System.err: 
System.err: StackTrace:
System.err: onBackgroundOrBorderPropertyChanged(file:///node_modules/@nativescript/core/ui/styling/background.js:88:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view/view.js:752:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view/view.js:732:0)
System.err: 	at applyAllNativeSetters(file:///node_modules/@nativescript/core/ui/core/properties/properties.js:1063:0)
System.err: 	at initNativeView(file:///node_modules/@nativescript/core/ui/core/properties/properties.js:990:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:628:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:273:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:232:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view/view.js:247:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/frame/frame-common.js:87:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:312:75)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:305:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:312:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:440:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:234:0)
System.err: 	at (file:///node_modules/nativescript-ui-sidedrawer/ui-sidedrawer.common.js:145:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view/view-common.js:1010:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:233:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view/view.js:247:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:312:75)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:305:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/core/view-base/view-base.js:312:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/frame/frame.js:872:0)
System.err: 	at (file:///node_modules/@nativescript/core/ui/frame/activity.js:29:0)
System.err: 	at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err: 	at com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:34)
System.err: 	at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
System.err: 	at android.app.Activity.performStart(Activity.java:7157)
System.err: 	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
System.err: 	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
System.err: 	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
System.err: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
System.err: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
System.err: 	at android.os.Handler.dispatchMessage(Handler.java:106)
System.err: 	at android.os.Looper.loop(Looper.java:193)
System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6669)
System.err: 	at java.lang.reflect.Method.invoke(Native Method)
System.err: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
System.err: Caused by: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"
System.err: 	... 21 more

This only affects the Android version of the app. The iOS version launches without any problems.

To Reproduce

Take an existing NativeScript project running 6.1, upgrade to 6.2 using tns update.

Expected behavior

Ideally it wouldn’t crash. 😅

Additional context

This error was also reported here in the android-runtime repo, but I’m not sure it’s actually an issue with the Android runtime (vs Android-specific code tns-core-modules) so I decided to post it here as well.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Hi All; ok thanks to @Brysem he narrowed down the actual library causing the issues. After a lot of tests and research, I have figured out what is going on… I have a temporary patch you can apply to your app that should fix the issue. I need to do some more testing to see the best way to fix this for good (for the next NS release); but this patch should allow you to move forward with your apps and has no negative issues that I can think of.

  1. Create a new files in your App_Resource/Android/ called native-api-usage.json so it should be like this: image
  2. Inside this file you want to add this:
{
    "whitelist": [
    ],
    "blacklist": [
       "androidx.core.view:ViewKt*",
       "androidx.core.os:HandlerKt*",
       "androidx.core.widget:TextViewKt*"
    ]
}
  1. tns clean android

  2. Go forward and create awesome non-crashing apps. 😀

We have figured out the lower level issue; and it is fixed in the next release.

In addition someone else ran into another kotlin helper issue; so I updated the exclude list post above with the third one to exclude until the next engine release.

@brysem - How frequently are you seeing this error in your app? Is this a app you can share with us at nStudio if we sign a NDA. The more consistent it fails and it being a core app would be something I would kill for while debugging this issue. 😀

Hi. I have managed to isolate the issue to a specific android package.

implementation 'androidx.core:core-ktx:1.3.1' https://developer.android.com/kotlin/ktx

By adding this, Nativescript will crash on launch of the application with the same stacktraces from above. The confusing thing is that there is no reference to the package in the stacktrace making it quite difficult to find.

Without actually calling any of the code from androidx.core:core-ktx, the crash also persists.

The plugin nativescript-advanced-webview uses triniwiz/fancy-advanced-webview which also uses implementation “androidx.core:core-ktx:1.2.0”

There seems to be a compatibility issue with Nativescript and androidx.core:core-ktx.

Do you still want a repository with a reproducible crash?

We discovered that with some Android animations another Kotlin class was interfering with the native classes; so I updated the above post; but basically add: "androidx.core.os:HandlerKt*" to the list to be excluded… You might never see this error depending on your app; but just to be on the safe side; I would add this one also. 😀

Nope, if this causes the issue then I should be able to duplicate the issue easily. Thank you for your deductive work. However if you are able to easily share a repo already setup to crash – that would save some time… But I’ll try and create a simple JS demo app wih the 1.3.1 core-ktx as a dependency and see what happens.

@tsonevn - thanks so much for looking into this! Sure enough, removing that plugin fixes the issue. I thought it might be a plugin, but I was thrown off since I didn’t see any plugin-related code in the stacktrace. (Besides ui-sidedrawer)

Turns out, it’s an issue with clashing androidx.appcompat dependencies, and it’s already been reported. I’ll close this issue and wait for an update to that plugin. Thanks again!

Hi @BenSjoberg, I’ve checked the provided info and was able to recreate the problem. It seems that the nativescript-advanced-webview causes this issue. After removing the plugin, the project works as expected. On that matter, I would suggest contacting the author by opening a new issue in the plugin’s repository.