NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
189 stars 107 forks source link

nativescript/ionic-portal crashes android app #538

Closed FerhatKoca closed 10 months ago

FerhatKoca commented 10 months ago

Hello, i'm currently trying to implement the ionic-portal plugin.

It works on ios, but if i try to start a android app it crashes and i get a error message:

System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to start activity ComponentInfo{com.myproject.app.saas/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
  System.err: ReferenceError: io is not defined
  System.err:
  System.err: StackTrace:
  System.err: register(file: src/webpack:/saas/node_modules/@nativescript/ionic-portals/index.android.js:5:0)
  System.err:   at (file: src/webpack:/saas/src/main.ts:21:4)

This is how i register my portal in the main.ts:

Application.on(Application.launchEvent, () => {
  IonicPortalManager.register(
    'key'
  );
});
NathanWalker commented 10 months ago

Thank you for the report. Could you try “rm -rf platforms” and then run android again?

FerhatKoca commented 10 months ago

Hey Nathan, thanks for the fast reply.

I already did that. Also with nodes. But it still wouldn't work. If i remove the code from main.ts than it builds the app. Very strange :D

Here is the rest of the error message, if it somehow helps:

System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to start activity ComponentInfo{com.myproject.app.saas/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
  System.err: ReferenceError: io is not defined
  System.err:
  System.err: StackTrace:
  System.err: register(file: src/webpack:/saas/node_modules/@nativescript/ionic-portals/index.android.js:5:0)
  System.err:   at (file: src/webpack:/saas/src/main.ts:20:4)
  System.err:   at invokeTask(file: src/webpack:/saas/node_modules/zone.js/fesm2015/zone.js:409:0)
  System.err:   at runTask(file: src/webpack:/saas/node_modules/zone.js/fesm2015/zone.js:178:0)
  System.err:   at invokeTask(file: src/webpack:/saas/node_modules/zone.js/fesm2015/zone.js:490:0)
  System.err:   at ZoneTask.invoke(file: src/webpack:/saas/node_modules/zone.js/fesm2015/zone.js:479:0)
  System.err:   at _handleEvent(file: src/webpack:/saas/node_modules/@nativescript/core/data/observable/index.js:306:40)
  System.err:   at notify(file: src/webpack:/saas/node_modules/@nativescript/core/data/observable/index.js:287:23)
  System.err:   at notifyLaunch(file: src/webpack:/saas/node_modules/@nativescript/core/application/application-common.js:194:13)
  System.err:   at createRootView(file: src/webpack:/saas/node_modules/@nativescript/core/application/application-common.js:202:32)
  System.err:   at setActivityContent(file: src/webpack:/saas/node_modules/@nativescript/core/ui/frame/index.android.js:1174:19)
  System.err:   at onCreate(file: src/webpack:/saas/node_modules/@nativescript/core/ui/frame/index.android.js:1003:13)
  System.err:   at onCreate(file: src/webpack:/saas/node_modules/@nativescript/core/ui/frame/activity.android.js:21:0)
  System.err:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
  System.err:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
  System.err:   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
  System.err:   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  System.err:   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  System.err:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
  System.err:   at android.os.Handler.dispatchMessage(Handler.java:106)
  System.err:   at android.os.Looper.loopOnce(Looper.java:201)
  System.err:   at android.os.Looper.loop(Looper.java:288)
  System.err:   at android.app.ActivityThread.main(ActivityThread.java:7872)
  System.err:   at java.lang.reflect.Method.invoke(Native Method)
  System.err:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  System.err:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
  System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed
  System.err: ReferenceError: io is not defined
  System.err:   at com.tns.Runtime.callJSMethodNative(Native Method)
  System.err:   at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1301)
  System.err:   at com.tns.Runtime.callJSMethodImpl(Runtime.java:1187)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1174)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1152)
  System.err:   at com.tns.Runtime.callJSMethod(Runtime.java:1148)
  System.err:   at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:57)
  System.err:   at android.app.Activity.performCreate(Activity.java:8305)
  System.err:   at android.app.Activity.performCreate(Activity.java:8284)
  System.err:   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
  System.err:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
  System.err:   ... 12 more
NathanWalker commented 10 months ago

Thanks that error would indicate the Android include.gradle didn't attach the plugin. Possible to share the package.json? As well as your App_Resources/Android/app.gradle?

FerhatKoca commented 10 months ago

Yeah sure.

app.gradle:

android {
  defaultConfig {
    minSdkVersion 21
    compileSdkVersion 33
    targetSdkVersion 33
    versionCode 12
    versionName "1.0.0"
    multiDexEnabled true
    generatedDensities = []
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }

  packagingOptions {
      pickFirst 'lib/x86/libc++_shared.so'
      pickFirst 'lib/x86_64/libc++_shared.so'
      pickFirst 'lib/armeabi-v7a/libc++_shared.so'
      pickFirst 'lib/arm64-v8a/libc++_shared.so'
  }
}

dependencies {
  implementation "androidx.core:core-splashscreen:1.0.0"
  implementation "com.github.mhiew:android-pdf-viewer:3.2.0-beta.1"
}

package.json:

{
  "name": "project-nx",
  "version": "1.10.0",
  "license": "MIT",
  "engines": {
    "node": ">=18.15.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "15.2.9",
    "@angular-eslint/eslint-plugin": "~15.2.1",
    "@angular-eslint/eslint-plugin-template": "~15.2.1",
    "@angular-eslint/template-parser": "~15.2.1",
    "@angular/cli": "~15.2.0",
    "@angular/compiler-cli": "15.2.1",
    "@angular/language-service": "15.2.1",
    "@html-eslint/eslint-plugin": "^0.16.0",
    "@html-eslint/parser": "^0.16.0",
    "@nativescript/eslint-plugin": "~0.0.4",
    "@nativescript/types": "~8.4.0",
    "@nativescript/webpack": "~5.0.12",
    "@ngtools/webpack": "^15.0.4",
    "@nrwl/angular": "15.9.2",
    "@nrwl/cli": "15.9.2",
    "@nrwl/cypress": "15.9.2",
    "@nrwl/eslint-plugin-nx": "15.9.2",
    "@nrwl/jest": "15.9.2",
    "@nrwl/js": "15.9.2",
    "@nrwl/linter": "15.9.2",
    "@nrwl/storybook": "15.9.2",
    "@nrwl/workspace": "15.9.2",
    "@nstudio/angular": "~15.0.2",
    "@nstudio/nativescript": "~15.0.2",
    "@nstudio/nativescript-angular": "~15.0.2",
    "@nstudio/web": "~15.0.2",
    "@nstudio/web-angular": "~15.0.2",
    "@nstudio/xplat": "~15.0.2",
    "@storybook/addon-essentials": "^6.5.15",
    "@storybook/angular": "^6.5.15",
    "@storybook/builder-webpack5": "^6.5.15",
    "@storybook/core-server": "^6.5.15",
    "@storybook/manager-webpack5": "^6.5.15",
    "@types/jest": "29.4.0",
    "@types/node": "~18.11.19",
    "@typescript-eslint/eslint-plugin": "~5.50.0",
    "@typescript-eslint/parser": "~5.50.0",
    "commitlint": "^17.4.4",
    "cypress": "^12.5.1",
    "eslint": "^8.33.0",
    "eslint-config-prettier": "8.6.0",
    "eslint-plugin-cypress": "^2.12.1",
    "eslint-plugin-html": "^7.1.0",
    "eslint-plugin-prettier": "^4.2.1",
    "html-webpack-plugin": "^5.5.0",
    "husky": "^8.0.0",
    "jest": "29.4.3",
    "jest-environment-jsdom": "29.4.3",
    "jest-preset-angular": "13.0.0",
    "lint-staged": "^13.1.0",
    "nativescript": "8.4.0",
    "nx": "15.9.2",
    "prettier": "^2.8.3",
    "sass": "^1.58.0",
    "standard-version": "^9.5.0",
    "ts-jest": "29.0.5",
    "ts-node": "~10.9.1",
    "typescript": "4.9.5",
    "webpack": "^5.64.0"
  },
  "dependencies": {
    "@angular/animations": "15.2.1",
    "@angular/cdk": "^15.2.0",
    "@angular/common": "15.2.1",
    "@angular/compiler": "15.2.1",
    "@angular/core": "15.2.1",
    "@angular/forms": "15.2.1",
    "@angular/localize": "^15.2.1",
    "@angular/platform-browser": "15.2.1",
    "@angular/platform-browser-dynamic": "15.2.1",
    "@angular/router": "15.2.1",
    "@apollo/client": "~3.7",
    "@material/elevation": "^14.0.0",
    "@nativescript-community/ui-pulltorefresh": "^2.5.3",
    "@nativescript-community/universal-links": "^3.0.0",
    "@nativescript/angular": "~15.0.1",
    "@nativescript/background-http": "^6.0.0",
    "@nativescript/camera": "^5.0.15",
    "@nativescript/core": "^8.4.3",
    "@nativescript/datetimepicker": "^2.1.12",
    "@nativescript/firebase-core": "^3.1.2",
    "@nativescript/firebase-messaging": "^3.1.2",
    "@nativescript/imagepicker": "^1.0.9",
    "@nativescript/ionic-portals": "^1.2.1",
    "@nativescript/iqkeyboardmanager": "^2.1.1",
    "@nativescript/pdf": "^1.0.1",
    "@nativescript/theme": "^3.0.2",
    "@ng-bootstrap/ng-bootstrap": "^14.2.0",
    "@ngneat/until-destroy": "^9.2.2",
    "@ngrx/component": "^15.0.0",
    "@ngrx/effects": "15.3.0",
    "@ngrx/store": "15.3.0",
    "@ngrx/store-devtools": "^15.3.0",
    "@ngx-translate/core": "~14.0.0",
    "@ngx-translate/http-loader": "~7.0.0",
    "@nstudio/nativescript-camera-plus": "4.1.6",
    "@nstudio/nativescript-checkbox": "^2.0.5",
    "@nstudio/nativescript-loading-indicator": "^4.1.2",
    "@triarensplugins/damage-reporting": "*",
    "angular-oauth2-oidc": "^15.0.1",
    "angular-svg-icon": "^15.0.0",
    "apollo-angular": "^4.2.0",
    "bootstrap": "^5.3.1",
    "core-js": "^3.27.1",
    "date-fns": "^2.29.3",
    "graphql": "^16.6.0",
    "js-search": "^2.0.0",
    "nativescript-inappbrowser": "^3.2.0",
    "nativescript-oauth2": "^3.0.10",
    "nativescript-phone": "^3.0.3",
    "nativescript-ui-chart": "^15.2.3",
    "nativescript-windowed-modal": "^7.0.0",
    "ngx-perfect-scrollbar": "^8.0.0",
    "rxjs": "^7.8.0",
    "tslib": "^2.4.1",
    "zone.js": "0.12.0"
  },
  "xplat": {
    "prefix": "project-nx",
    "framework": "angular"
  },
  "lint-staged": {
    "{apps,libs}/**/*.{ts,html}": [
      "npx prettier --write",
      "npx eslint --quiet --cache --fix"
    ]
  },
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },
  "overrides": {
    "jest-preset-angular": {
      "jest": "^29.0.0",
      "ts-jest": "^29.0.0"
    },
    "@storybook/angular": {
      "zone.js": "0.12.0"
    }
  }
}
NathanWalker commented 10 months ago

Thanks, in an Nx workspace all NativeScript dependencies must also be in the apps/nativescript-{name}/package.json as well. So that should also contain "@nativescript/ionic-portals": "^1.2.1",

otherwise cli will not attach native platform dependencies to the app build itself leading to error you mentioned. Be sure app inside workspace is cleaned after ensuring package dep is added (at root and in the app)

FerhatKoca commented 10 months ago

Hey, thanks, that worked. Also had to bump up the minSdk version to 22.

Thank you and the NS-Team. You are doing a great job !!