Nativescript: java.lang.NoSuchMethodError after upgrade to 6.5.10

Created on 14 Jul 2020  Â·  28Comments  Â·  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):
✔ Component nativescript has 6.7.8 version and is up to date.
✔ Component @nativescript/core has 6.5.10 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.

  • Plugin(s):
    "@angular/animations": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/forms": "~8.2.0",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "@nativescript/core": "6.5.10",
    "@nativescript/theme": "^2.3.3",
    "@nativescript/angular": "^8.21.0",
    "@nstudio/nativescript-checkbox": "^1.0.0",
    "@nstudio/nativescript-loading-indicator": "^1.0.0",
    "email-validator": "^2.0.4",
    "moment": "^2.24.0",
    "nativescript-appversion": "^1.4.2",
    "nativescript-background-http": "^4.2.1",
    "nativescript-barcodescanner": "3.4.1",
    "nativescript-fingerprint-auth": "7.0.2",
    "nativescript-iqkeyboardmanager": "^1.4.0",
    "nativescript-localize": "^4.2.0",
    "nativescript-pdf-view": "2.1.0",
    "nativescript-permissions": "^1.3.8",
    "nativescript-secure-storage": "2.6.0",
    "nativescript-ui-listview": "8.2.0",
    "nativescript-ui-sidedrawer": "8.0.1",
    "nativescript-unit-test-runner": "^0.7.0",
    "nativescript-zip": "^3.0.3",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.4.0",
    "tns-platform-declarations": "6.5.10",
    "zone.js": "^0.9.1"

Describe the bug

After upgrading to 6.5.10, I get exceptions like

JS: Error: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"

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)

and

System.err: Calling js method onAnimationEnd failed
System.err: Error: java.lang.NoSuchMethodError: no static method "Landroid/os/Handler;.postDelayed(Ljava/lang/Runnable;J)Z"
System.err: 
System.err: StackTrace:
System.err: setTimeout(file: node_modules/@nativescript/core/timer/timer.android.js:33:0)
System.err:     at scheduleTask(file: node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1582:0)
Sys

and

JS: ERROR Error: java.lang.NoSuchMethodError: no static method "Landroid/os/Handler;.postDelayed(Ljava/lang/Runnable;J)Z"

and

07-14 17:49:12.370 26823 26823 W System.err: Calling js method onStart failed
07-14 17:49:12.370 26823 26823 W System.err: Error: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"
07-14 17:49:12.370 26823 26823 W System.err: 
07-14 17:49:12.370 26823 26823 W System.err: StackTrace:
07-14 17:49:12.370 26823 26823 W System.err: onBackgroundOrBorderPropertyChanged(file:///data/data/de.debeka.fotoapp/files/app/vendor.js:121540:20)
07-14 17:49:12.370 26823 26823 W System.err:    at push.../node_modules/@nativescript/core/ui/core/view/view.js.View._redrawNativeBackground(file:///data/data/de.debeka.fotoapp/files/app/vendor.js:111656:29)

With Version @nativescript/core 6.5.1 everything runs fine.

To Reproduce

Expected behavior
No exceptions ;-)

Additional context

  • Tried to set
project.ext {
        androidXRecyclerViewVersion = "1.1.0"
        androidXAppCompatVersion = "1.1.0"
    }
  • --no-hmr does not help, the error also occurs with a production build and is reported from the Google Play Console "Pre-Launch-Report"

  • for some exceptions I see

07-14 18:44:00.278 30019 30019 E JS      : ERROR Error: java.lang.NoSuchMethodError: no static method "Landroid/os/Handler;.postDelayed(Ljava/lang/Runnable;J)Z"
07-14 18:44:00.282 30019 30019 E JS      : ERROR Error: java.lang.NoSuchMethodError: no static method "Landroid/os/Handler;.postDelayed(Ljava/lang/Runnable;J)Z"
07-14 18:44:00.286 30019 30019 E JS      : ERROR CONTEXT [object Object]

while I have no clue where the "ERROR CONTEXT" originates from

Most helpful comment

I have traced down the actual issue in the Android runtime, the next version should have a fix that will allow you to not have to black list any data. :grinning:

In addition we discovered another metadata issue that was inflating the metadata by about 20k for apps that will be resolved, might be a bit more on full apps but probably not much more.

All 28 comments

Hi @madmas
Thank you for reporting this issue.
We are going to try replicate this case on our end and will confirm. We will research what is causing this issue and will provide the needed fix. For further info, you could keep track the issue.

Hi @Ross-Olivares , thank you for picking this up. let me know if i can help with any information. I can provide an additional stacktrace: https://gist.github.com/madmas/66bb6c3ad26b6bf0e75988a87e96518c

@madmas have you irectly migrated from 6.5.1 to 6.5.10 or have you tried some of the versions in between? Maybe that helps to figure out what is causing this.
I am not from the NS team, but I am also concerned to get the same errors in our release app when upgrating.

@felixkrautschuk unfortunately, I've to extend the range where the error was introduced - the last very stable version I can refer to 6.1. I was stuck on that version for other reasons so that the next version I could jump to was 6.5 - and the error occurs in every 6.5.X version so far.
I also get reports from the Google Play Console - Pre-Launch-Reports that show these errors.
Also looking for further indicators on how to get this fixed....

Hi @madmas Thanks for the stacktrace information, however we would like if you can send us a sample project that can help us to reproduce the issue.

Experiencing same issue

Uncaught exception: Error: Calling js method onCreateView failed
Error: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"
Uncaught exception: Error: Calling js method onStart failed
Error: java.lang.NoSuchMethodError: no static method "Landroid/view/View;.setPadding(IIII)V"

And literally in the same boat as @madmas, most stable version was for project I work with is 6.1.1. Now with upgrade I experience those issues.

Wondering what devices you are seeing that on? Would like to know the model and android version.
The issue seems to be that we are looking for static methods for non static methods.
Going back to old versions of the core should not change a thing.
Changing the android runtime version could make a difference though

Any Android device physical or not. When running tns debug instead of tns run or installing it on device, it's happening much more often. And yes. Android runtime is 6.1.
But can we run in the mean time core 6.5, ios-runtime 6.5 and android-runtime 6.1? Since the biggest problem with those upgrades is that you need ios-runtime 6.5 because of iOS 14.

Same here, various devices (Pixel 3a, Sony devices, Samsung devices, also emulators) with different Android Versions (from 7.1 to 10).

I went through the list of nativescript plugins that we have in common. Here they are:

"nativescript-fingerprint-auth": "7.0.2",
"nativescript-ui-listview": "7.1.0", <- different major version for me
"nativescript-ui-sidedrawer": "7.0.1", <- also different major version for me
"rxjs": "6.5.3",

I have the same problem using {N}Vue. I think that my problem starts when I ran npm audit fix :'( I never tried to update before.
My environment is with version 6.7.4 of {N} and my android version and tns-core-modules is 6.5.0.
I tried to update to lastest {N} version 6.8.0, android 6.5.3 and tns-core-modules 6.5.13 but the problem continues, so I decided downgrade again to 6.7.4, 6.50 and 6.5.0 respectively.

I have these plugins in common with you:
"nativescript-fingerprint-auth": "7.0.2", "nativescript-ui-listview": "^8.2.0", "nativescript-ui-sidedrawer": "~8.0.1",

I'll be attentive for updates of this issue.

I can say that these plugins to not cause it, or at leat not exclusive, as I got a small app that causes it without these plugins.

I have an update I have a duplicatable case with a minimal JS application, crashes on startup all the time. No extra NS plugins... But forcing a external google/android aar that many plugins might be automagically bringing in to the app hence the reason we were having an issue pinpointing the cause -- so this google aar is somehow messing something up...

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*"
    ]
}
  1. tns clean android

  2. Go forward and create awesome non-crashing apps. :grinning:

Hi,
thanks a lot for digging into this @brysem and @NathanaelA !

we just tried to apply this and got, unfortunately just got ein of those exceptoins again:

com.tns.NativeScriptException: Calling js method onTransitionEnd failed Error: java.lang.NoSuchMethodError: no static method "Landroid/os/Handler;.postDelayed(Ljava/lang/Runnable;J)Z"

full stacktrace: https://gist.github.com/madmas/75c2917848f6393759dd4297bb228660

will do further tests, of course.

@madmas looking at the blacklist class you can try something like

{
    "whitelist": [
    ],
    "blacklist": [
       "androidx.core.view:ViewKt*",
       "androidx.core.os:HandlerKt*"
    ]
}

@triniwiz thanks a lot for the suggestion! currently building the artifacts to test. Out of curiosity: what exactly do we block with that entries (from the filename and the entries, I'd assume we block API calls going from TNS to the classes named in the list, right? ;-) ) and why is it not causing side-effects?

@NathanaelA can go in depth but think about it this way the metadata would scan the app on build to know what is exposed in the app then it would add that to a data file what the app then uses (think like a key/val) so it seems like when the kotlin core is included it would override the default that comes with with android java core ... so ignoring should not cause an issue ... test an let us know 🙂

@madmas - Thanks for the report; it looks like what Osie suggested is exactly what I would have suggested. Appears to be related to certain transition Animations, which is why my stock app didn't hit it.

Basically what is happening is that when a later versions of Kotlin core gets linked in has a override function called setPadding(int) not the standard setPadding(int, int, int, int). This creates some weird corruption, still trying to figure out what exactly. Any additional NS plugin that uses Kotlin, might then link in the later version of the Kotlin core; and when that happened the metadata generator would see the new setPadding(int) and it appears that something is corrupted in the metadata then at that point.

I'm stepping through the metadata generator to understand if the metadata is getting replaced or what is causing the setPadding(i,i,i,i) to no longer be valid -- but you can imagine the amount of metadata generated, so this is time consuming. :D We will provide an official fix for the next version of NativeScript, which might end up just hard coding these in the black list if we find it is the best solution.

This solution that I provided is 100% official workaround so you all can get back to work and not wait until I can figure out what we ship in the next version of NS. I can't think of anything negative that it could do to any NS applications, so I would feel very confortable shipping a million dollar client app using this technique...

As for what we are doing, NativeScript has a feature to allow you to ignore metadata; if you want to make your app a lot smaller; you can have NS remove certain metadata that your app isn't using; for example this is a feature that all the ProPlugins has setup already; so if you pulled a demo from you ProPlugins you would see this as your metadata sizes:
(ProPlugins Demo, with metadata filtering enabled)
image
vs
(normal demo app)
image
(a > 50% savings in metadata sizes). :grinning:

So what we are doing here; is using this metadata filtering to only filter out certain Kotlin runtime HELPER metadata; the functions are still present in the application, so any Kotlin code will still have access and linked to them. However, NativeScript then has no knowledge of these helper functions. Basically all we have done is eliminated about 10 or so kotlin helper functions from being added to the metadata; so that we don't replace the real setPadding functions metadata entry.

@triniwiz @NathanaelA thanks a lot for the explanations and of course for the work done here :) Our tests were successful to I can confirm that this workarouns is working! thank you 🎉

@NathanaelA, @triniwiz you're a gods :)
With latest suggestions I'm not getting any errors. Will test it a bit more in next few days to see if everything is actually resolved. But I was running tns debug Android with hmr for few hours and different scenarios and didn't receive any postDelayed or setPadding errors.

I do the latest suggestions and I'm still getting another 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/widget/TextView;.addTextChangedListener(Landroid/text/TextWatcher;)V"
System.err: StackTrace:
System.err: EditableTextBase.initNativeView(file: node_modules/@nativescript/core/ui/editable-text-base/editable-text-base.android.js:123:17)
System.err:     at ViewBase.setNativeView(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:548:17)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:527:13)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:534:18)
System.err:     at LayoutBaseCommon.eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:125:25)
System.err:     at ViewCommon.eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:1010:13)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:533:13)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:534:18)
System.err:     at LayoutBaseCommon.eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:125:25)
System.err:     at ViewCommon.eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:1010:13)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:533:13)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:534:18)
System.err:     at LayoutBaseCommon.eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:125:25)
System.err:     at ViewCommon.eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:1010:13)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:533:13)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:534:18)
System.err:     at LayoutBaseCommon.eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:125:25)
System.err:     at ViewCommon.eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:1010:13)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:533:13)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:534:18)
System.err:     at ContentView.eachChildView(file: node_modules/@nativescript/core/ui/content-view/content-view.js:70:12)
System.err:     at PageBase.eachChildView(file: node_modules/@nativescript/core/ui/page/page-common.js:126:39)
System.err:     at ViewCommon.eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:1010:13)
System.err:     at ViewBase._setupUI(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:533:13)
System.err:     at ViewBase._addViewCore(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:432:17)
System.err:     at ViewBase._addView(file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:421:13)
System.err:     at FragmentCallbacksImplementation.onCreateView(file: node_modules/@nativescript/core/ui/frame/frame.android.js:689:18)
System.err:     at FragmentClass.onCreateView(file: node_modules/@nativescript/core/ui/frame/fragment.android.js:29:37)
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:2439)
System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
System.err:     at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
System.err:     at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
System.err:     at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
System.err:     at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
System.err:     at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
System.err:     at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
System.err:     at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
System.err:     at android.os.Handler.handleCallback(Handler.java:743)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
System.err:     at android.os.Looper.loop(Looper.java:150)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:5546)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
System.err: Caused by: java.lang.NoSuchMethodError: no static method "Landroid/widget/TextView;.addTextChangedListener(Landroid/text/TextWatcher;)V"

It don't happens always, I really couldn't yet identify when it happens. is it related?
Thanks

@comiguel for you it will be the following

{
    "whitelist": [
    ],
    "blacklist": [
       "androidx.core.view:ViewKt*",
       "androidx.core.os:HandlerKt*",
       "androidx.core.widget:TextViewKt*"
    ]
}

I have traced down the actual issue in the Android runtime, the next version should have a fix that will allow you to not have to black list any data. :grinning:

In addition we discovered another metadata issue that was inflating the metadata by about 20k for apps that will be resolved, might be a bit more on full apps but probably not much more.

Hi @triniwiz, @NathanaelA a new Error Exception appears on a user tester:

An uncaught Exception occurred on "main" thread. Calling js method onCreateView failed Error: java.lang.NoSuchMethodError: no static method "Landroid/graphics/Typeface;.create()V" StackTrace: createTypeface(file:///data/data/com.global66.cards/files/app/vendor.js:38161:44) at Font.getAndroidTypeface(file:///data/data/com.global66.cards/files/app/vendor.js:38082:24) at TextBase.<computed>(file:///data/data/com.global66.cards/files/app/vendor.js:44839:85) at applyAllNativeSetters(file:///data/data/com.global66.cards/files/app/vendor.js:20014:31) at initNativeView(file:///data/data/com.global66.cards/files/app/vendor.js:19918:5) at ViewBase.onResumeNativeUpdates(file:///data/data/com.global66.cards/files/app/vendor.js:21030:18) at ViewBase._resumeNativeUpdates(file:///data/data/com.global66.cards/files/app/vendor.js:20561:12) at ViewBase.onLoaded(file:///data/data/com.global66.cards/files/app/vendor.js:20507:10) at View.onLoaded(file:///data/data/com.global66.cards/files/app/vendor.js:22926:31) at (file:///data/data/com.global66.cards/files/app/vendor.js:20610:20) at ViewBase.callFunctionWithSuper(file:///data/data/com.global66.cards/files/app/vendor.js:20599:5)

Wich line I have to put in the blacklist?. We can't update yet for some unsupported plugins on {N}7

Thanks for your valuable help.

@comiguel , You can also use the NS 7 Android runtime with NS 6. Just manually download it from npm:
https://registry.npmjs.org/@nativescript/android/-/android-7.0.0.tgz
and then do a tns platform add android --frameworkPath=<path to android-7.0.0.tgz>
However, if you want to do the blacklist instead, use the last post Osie did https://github.com/NativeScript/NativeScript/issues/8709#issuecomment-675751262 with all three entries

@NathanaelA I got this error trying to compile NS 7 Android runtime with NS6:

Build file '/Users/comiguel/Documents/Projects/mobile-customer/platforms/android/app/build.gradle' line: 633
A problem occurred configuring project ':app'.
NotAfter: Fri Sep 11 07:00:00 COT 2020

I don't know what I have to do, I can't update to NS7 yet for plugins incompatibilities :'(

I just took one of my personal NativeScript 6 apps that I use all the time on my phone and has a myrid of plugins in it, and custom java files added to the app_resource folder; so it has the kitchen sink and basically anything that can go wrong should go wrong. :)

  • npm i -g nativescript@latest -- This gave me the latest NativeScript CLI
    image

  • cd /my/cool/app

  • wget https://registry.npmjs.org/@nativescript/android/-/android-7.0.0.tgz
  • (deleted the app's platforms folder)
  • tns platform add android --frameworkPath=./android-7.0.0.tgz
  • tns build android
    image
    And now I have a version of the app using the NS7 runtime, but using the NS6 core modules.
    Please note; normally you don't want to have different versions of the Android/iOS Runtime vs the Core modules; but in this specific case the v7 engine is 100% backwards compatible with NS 6 core in Android. The NS 7 CLI itself can build NS6&NS7 apps; so it is safe to upgrade even if you are wanting to stay with NS6 core modules.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielzzz picture danielzzz  Â·  59Comments

lscown picture lscown  Â·  163Comments

tjvantoll picture tjvantoll  Â·  58Comments

morningrat picture morningrat  Â·  67Comments

atanasovg picture atanasovg  Â·  50Comments