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

Created on 19 Nov 2019  ยท  15Comments  ยท  Source: NativeScript/NativeScript

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.

android

Most helpful comment

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. :grinning:

All 15 comments

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.

@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!

I am not using the plugin nativescript-advanced-webview and am getting the error.

I am experiencing this issue as wel on Android.

โœ” Getting NativeScript components versions information...
โœ” Component nativescript has 6.8.0 version and is up to date.
โœ” Component tns-core-modules has 6.5.15 version and is up to date.
โœ” Component tns-android has 6.5.3 version and is up to date.
โœ” Component tns-ios has 6.5.2 version and is up to date.

Dependencies

"@nativescript/theme": "~2.3.0",
"tns-core-modules": "6.5.15"

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.android.js:86:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View._redrawNativeBackground(file: node_modules/@nativescript/core/ui/core/view/view.android.js:777:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View.<computed>(file: node_modules/@nativescript/core/ui/core/view/view.android.js:757:0) System.err: at applyAllNativeSetters(file: node_modules/@nativescript/core/ui/core/properties/properties.js:1065:0) System.err: at initNativeView(file: node_modules/@nativescript/core/ui/core/properties/properties.js:992:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.onResumeNativeUpdates(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:647:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase._resumeNativeUpdates(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:278:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.onLoaded(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:232:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View.onLoaded(file: node_modules/@nativescript/core/ui/core/view/view.android.js:249:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/frame-common.js.FrameBase.onLoaded(file: node_modules/@nativescript/core/ui/frame/frame-common.js:84:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/frame.js.Frame.onLoaded(file: node_modules/@nativescript/core/ui/frame/frame.android.js:186:0) System.err: at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:75) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callFunctionWithSuper(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:310:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callLoaded(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/frame.js.ActivityCallbacksImplementation.onStart(file: node_modules/@nativescript/core/ui/frame/frame.android.js:888:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/activity.js.NativeScriptActivity.onStart(file: node_modules/@nativescript/core/ui/frame/activity.android.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:29) System.err: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433) System.err: at android.app.Activity.performStart(Activity.java:7980) System.err: at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3578) System.err: at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) System.err: at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) System.err: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2220) System.err: at android.os.Handler.dispatchMessage(Handler.java:107) System.err: at android.os.Looper.loop(Looper.java:237) System.err: at android.app.ActivityThread.main(ActivityThread.java:8016) 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:1076) System.err: Caused by: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V" System.err: ... 21 more

@brysem - Is your app, using Angular, Vue, or Core?

@brysem - Is your app, using Angular, Vue, or Core?

My app is using only core and has been generated using nativescript-plugin-seed

@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. :grinning:

@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?

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.

@brysem - Your instructions were perfect; THANK YOU! I was able to duplicate it on a stock JS app; just adding the single library...
Investigating right now.. :grinning:

Hi!
After upgrading my NativeScript project to 6.8, my app crashes on Android with the same error:

System.err: An uncaught Exception occurred on "main" thread. System.err: Calling js method onCreateView 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.android.js:86:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View._redrawNativeBackground(file: node_modules/@nativescript/core/ui/core/view/view.android.js:777:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View.<computed>(file: node_modules/@nativescript/core/ui/core/view/view.android.js:757:0) System.err: at applyAllNativeSetters(file: node_modules/@nativescript/core/ui/core/properties/properties.js:1065:0) System.err: at initNativeView(file: node_modules/@nativescript/core/ui/core/properties/properties.js:992:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.onResumeNativeUpdates(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:647:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase._resumeNativeUpdates(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:278:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.onLoaded(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:232:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view/view.js.View.onLoaded(file: node_modules/@nativescript/core/ui/core/view/view.android.js:249:0) System.err: at push.../node_modules/@nativescript/core/ui/page/page.js.Page.onLoaded(file: node_modules/@nativescript/core/ui/page/page.android.js:43:0) System.err: at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:75) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callFunctionWithSuper(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:310:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.callLoaded(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.loadView(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:456:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase._addViewCore(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:451:0) System.err: at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase._addView(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:437:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/frame.js.FragmentCallbacksImplementation.onCreateView(file: node_modules/@nativescript/core/ui/frame/frame.android.js:700:0) System.err: at push.../node_modules/@nativescript/core/ui/frame/fragment.js.FragmentClass.onCreateView(file: node_modules/@nativescript/core/ui/frame/fragment.android.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.FragmentClass.onCreateView(FragmentClass.java:53) System.err: at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2595) System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881) System.err: at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238) System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303) System.err: at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439) System.err: at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2076) System.err: at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866) System.err: at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1821) System.err: at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727) System.err: at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150) System.err: at android.os.Handler.handleCallback(Handler.java:751) System.err: at android.os.Handler.dispatchMessage(Handler.java:95) System.err: at android.os.Looper.loop(Looper.java:154) System.err: at android.app.ActivityThread.main(ActivityThread.java:6816) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451) System.err: Caused by: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V" System.err: ... 24 more

Environment :
โœ” Component nativescript has 6.8.0 version and is up to date.
โœ” Component tns-core-modules has 6.5.15 version and is up to date.
โœ” Component tns-android has 6.5.3 version and is up to date.
โœ” Component tns-ios has 6.5.2 version and is up to date.

Here, I'm using the nativescript-advanced-webview plugin.

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. :grinning:

@NathanaelA You're amazing! Thanks for the dedication.

@NathanaelA @brysem A huge thank you! It works!

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. :grinning:

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickIliev picture NickIliev  ยท  58Comments

atanasovg picture atanasovg  ยท  50Comments

lscown picture lscown  ยท  58Comments

mspusta78 picture mspusta78  ยท  59Comments

AbanoubNassem picture AbanoubNassem  ยท  53Comments