Open
Description
Environment
{
"name": "ns-shared",
"nativescript": {
"id": "org.nativescript.nsshared",
"tns-android": {
"version": "5.0.0"
}
},
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"android": "tns run android --bundle",
"ios": "tns run ios --bundle"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"@swimlane/ngx-datatable": "^14.0.0",
"core-js": "^2.5.4",
"nativescript-angular": "~7.0.0",
"nativescript-camera": "^4.1.1",
"nativescript-myplugin": "file:../plugin/myplugin/publish/package/nativescript-myplugin-1.0.0.tgz",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-chart": "^3.10.0",
"nativescript-ui-dataform": "^3.9.0",
"nativescript-ui-listview": "^4.0.0",
"nativescript-ui-sidedrawer": "^5.0.0",
"nativescript-webview-utils": "^3.0.0",
"reflect-metadata": "~0.1.8",
"rxjs": "^6.2.0",
"tns-core-modules": "~5.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.8.0",
"@angular/cli": "^7.0.0",
"@angular/compiler-cli": "~7.0.0",
"@nativescript/schematics": "~0.3.0",
"@types/jasmine": "2.8.11",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"nativescript-dev-sass": "^1.6.0",
"nativescript-dev-typescript": "~0.7.0",
"nativescript-dev-webpack": "^0.17.0",
"protractor": "~5.3.0",
"tns-platform-declarations": "^5.0.2",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~3.1.1"
}
}
Describe the bug
I extend android application using this code:
./src/app/application.android.js
const superProto = android.app.Application.prototype;
//this is my custom plugin
var nativedModule = require("nativescript-myplugin");
android.app.Application.extend("org.myApp.Application", {
onCreate: function() {
superProto.onCreate.call(this);
console.log("Overwritten application");
},
attachBaseContext: function(base) {
superProto.attachBaseContext.call(this, base);
}
});
this is webpack.config.js
entry: {
bundle: entryPath,
application:resolve(__dirname, "./src/app/application.android.js"),
}
this is AndroidManifest.xml
<application
android:name="org.myApp.Application"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
when refreshing (tns run android --bundle) the app on device I get the below error, if I remove the require instruction for my custom plugin "myplugin" the refresh works without any problems.
If I import my pluging in any other app's components there are no problems and everything works.
Can you help me?
This is the error:
Successfully transferred application.js on device emulator-5556.
Refreshing application on device emulator-5556...
System.err: com.tns.NativeScriptException: Failed to create JavaScript extend wrapper for class 'org/myApp/Application'
System.err: at com.tns.Runtime.createJSInstanceNative(Native Method)
System.err: at com.tns.Runtime.createJSInstance(Runtime.java:656)
System.err: at com.tns.Runtime.initInstance(Runtime.java:629)
System.err: at com.tns.RuntimeHelper.initRuntime(RuntimeHelper.java:211)
System.err: at org.myApp.Application.onCreate(Application.java:21)
System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
System.err: at android.app.ActivityThread.access$1100(ActivityThread.java:199)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
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)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.callJSMethodNative(Native Method)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:983)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:967)
12-01 08:58:10.895 30541 30541 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:959)
System.err: java.lang.RuntimeException: Unable to create application org.myApp.Application: com.tns.NativeScriptException: JavaScript object for Java ID 0 not found.
System.err: Attempting to call method onCreate
System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876)
System.err: at android.app.ActivityThread.access$1100(ActivityThread.java:199)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
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: com.tns.NativeScriptException: JavaScript object for Java ID 0 not found.
System.err: Attempting to call method onCreate
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:983)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:967)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:959)
System.err: at org.myApp.Application.onCreate(Application.java:27)
System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
System.err: ... 8 more
Successfully synced application org.nativescript.nsshared on device emulator-5556.