Error: trying to link invalid ‘this’ to a java object (async/await, importHelpers)


#1

Any tips on debugging an “Error: trying to link invalid ‘this’ to a java object” upon starting my app on android? It runs fine on iOS. I’ve seen a few other posts about the same error message, but they seem unrelated to what I’m running into (or maybe I’m just not seeing the relation…) Here’s what I’ve tried:

  • rolled back previous commits to a known good state
  • deleted node_modules folder and removed then re-added the platform
  • uninstalled tns and reinstalled it
  • commented out all of my code

I’m not sure what to try next apart from creating a new app and copying in my entire codebase piece by piece, so any advice is appreciated! Here’s the output I get:

System.err: java.lang.RuntimeException: Unable to resume activity {io.nick.app/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
System.err: Calling js method onActivityResumed failed
System.err: Error: Trying to link invalid 'this' to a Java object
System.err: File: "file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js, line: 237, column: 35
System.err: StackTrace: 
System.err: 	Frame: function:'AnimationListnerImpl', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 237, column: 36
System.err: 	Frame: function:'getAnimationListener', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 268, column: 29
System.err: 	Frame: function:'setupExitAndPopEnterAnimation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 474, column: 20
System.err: 	Frame: function:'setupAllAnimation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 489, column: 5
System.err: 	Frame: function:'_setAndroidFragmentTransitions', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 103, column: 9
System.err: 	Frame: function:'Frame._navigateCore', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 128, column: 32
System.err: 	Frame: function:'FrameBase.performNavigation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 275, column: 14
System.err: 	Frame: function:'FrameBase._processNavigationContext', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 261, column: 18
System.err: 	Frame: function:'resume_1', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 238, column: 68
System.err: 	Frame: function:'Observable.notify', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
System.err: 	Frame: function:'', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/application/application.js', line: 197, column: 24
System.err: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3121)
System.err: 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)
System.err: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
System.err: 	at android.app.ActivityThread.-wrap11(ActivityThread.java)
System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
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:5443)
System.err: 	at java.lang.reflect.Method.invoke(Native Method)
System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
System.err: Caused by: com.tns.NativeScriptException: 
System.err: Calling js method onActivityResumed failed
System.err: Error: Trying to link invalid 'this' to a Java object
System.err: File: "file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js, line: 237, column: 35
System.err: StackTrace: 
System.err: 	Frame: function:'AnimationListnerImpl', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 237, column: 36
System.err: 	Frame: function:'getAnimationListener', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 268, column: 29
System.err: 	Frame: function:'setupExitAndPopEnterAnimation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 474, column: 20
System.err: 	Frame: function:'setupAllAnimation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 489, column: 5
System.err: 	Frame: function:'_setAndroidFragmentTransitions', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js', line: 103, column: 9
System.err: 	Frame: function:'Frame._navigateCore', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 128, column: 32
System.err: 	Frame: function:'FrameBase.performNavigation', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 275, column: 14
System.err: 	Frame: function:'FrameBase._processNavigationContext', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 261, column: 18
System.err: 	Frame: function:'resume_1', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 238, column: 68
System.err: 	Frame: function:'Observable.notify', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
System.err: 	Frame: function:'', file:'file:///data/data/io.nick.app/files/app/tns_modules/tns-core-modules/application/application.js', line: 197, column: 24
System.err: 	at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
System.err: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:957)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:941)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:933)
System.err: 	at com.tns.gen.android.app.Application_ActivityLifecycleCallbacks.onActivityResumed(Application_ActivityLifecycleCallbacks.java:24)
System.err: 	at android.app.Application.dispatchActivityResumed(Application.java:214)
System.err: 	at android.app.Activity.onResume(Activity.java:1211)
System.err: 	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1281)
System.err: 	at android.app.Activity.performResume(Activity.java:6320)
System.err: 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3110)
System.err: 	... 10 more
ActivityManager: Process io.nick.app (pid 14604) has died
ActivityManager: cleanUpApplicationRecord -- 14604
^CExecuting after-watch hook from /Users/nick/dev/app/hooks/after-watch/nativescript-dev-typescript.js
Stopping tsc watch
Executing after-watch hook from /Users/nick/dev/app/hooks/after-watch/nativescript-dev-typescript.js

#2

@freshlytyped
Are you overriding onActivityResumed event in your code?


#3

No I’m not overriding that event.


#4

@freshlytyped
Can you provide the output you get for
tns info in your project directory please.


#5

@multishiv19 here is the output. Note that the error about nativescript-starter-kits is not related, since it only appeared recently after I ran nativescript Sidekick.

tns info
Error while loading nativescript-starter-kits is: Cannot find module '/Users/nick/.local/share/.nativescript-cli/extensions/node_modules/nativescript-starter-kits'
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component        │ Current version │ Latest version │ Information │
│ nativescript     │ 3.3.0           │ 3.3.0          │ Up to date  │
│ tns-core-modules │ 3.3.0           │ 3.3.0          │ Up to date  │
│ tns-android      │ 3.3.1           │ 3.3.1          │ Up to date  │
│ tns-ios          │ 3.3.0           │ 3.3.0          │ Up to date  │
└──────────────────┴─────────────────┴────────────────┴─────────────┘

#6

@freshlytyped
Try this once
tns platform remove android

tns platform add android@3.3.0

tns run android


#7

@multishiv19 same result. I just tried rolling back to 3.2.0 as well, and same result.


#8

Also @freshlytyped, which android device are you trying to run this on?


#9

@multishiv19 two different Moto X Pures running Android 6, and a virtual device running android 7. I’ve successfully run the app on these devices in the past.


#10

@freshlytyped did you update any plugin recently, or installed a new one?


#11

None that I’ve been able to identify yet (I don’t believe I’ve manually updated anything). But that must be what happened. I’m going to start rolling back plugin versions one by one before I take the “create a new app and copy everything in piece by piece” route.


#12

sure @freshlytyped keep us posted on how it goes


#13

@multishiv19 I found the problem (or at least how to turn it on and off). In tsconfig.json “compilerOptions”, I have importHelpers set to true so that I can use async/await syntax without defining my own __awaiter. When I remove "importHelpers": true from tsconfig.json (and comment-out my async code), it runs fine on android. Not sure when exactly this stopped working, because I’ve had importHelpers set to true for a while.

Steps to reproduce:

  • create a new tns angular project with tns create projectname --ng.
  • in tsconfig.json’s compilerOptions, add "importHelpers": true.
  • run on an android device with tns run android

#14

@freshlytyped I wasn’t aware that you were using NS Ng,
@Pete.K do you know anything about this?

In NS Core, I’m able to use async functions easily.
In my eslintrc, I just set the version of ecma script to 2017, and I was good to go with async functions.


#15

@multishiv19 off topic how do you exactly enabled ecma script to 2017, I’m already having troubles with ES6 as I don’t find all the syntax to be supported thats why I’m stuck working with ES5 :frowning:

here is a link to my original topic ECMAScript 6 (ES6) importing problems


#16

@ganas
we can continue this on your topic


#17

Prior to logging this issue in github, I finally stumbled upon this closed issue that’s the exact problem I encountered: https://github.com/NativeScript/NativeScript/issues/3846 . The person that logged it later closed it themselves after finding a workaround (they just define their own explicit __awaiter rather than using importHelpers). So although it hasn’t actually been fixed, I’m content with the workaround.

After @multishiv19 mentioned that he targets es2017, I discovered that simply targeting es2017 in your tsconfig.json makes async/await work without importHelpers and without defining your own __awaiter. Not sure if this solution will cause other problems but I haven’t encountered any yet (whats the official es version supported by NS?).


#18

@freshlytyped
Pete has answered your questions here