NativeScript / capacitor

NativeScript for Capacitor
https://capacitor.nativescript.org
38 stars 9 forks source link

Android native calls seem to not work. NativeCapEvents are produced, but no native functions are being called. #6

Open radarsu opened 3 years ago

radarsu commented 3 years ago

General info

Device: Xiaomi Redmi 5 package.json:

{
  "name": "nativescript-capacitor-ionic",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:nativescript": "build-nativescript",
    "build:mobile": "npm-run-all build build:nativescript"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~12.0.1",
    "@angular/core": "~12.0.1",
    "@angular/forms": "~12.0.1",
    "@angular/platform-browser": "~12.0.1",
    "@angular/platform-browser-dynamic": "~12.0.1",
    "@angular/router": "~12.0.1",
    "@capacitor/android": "^3.1.1",
    "@capacitor/app": "1.0.2",
    "@capacitor/core": "3.1.1",
    "@capacitor/haptics": "1.0.2",
    "@capacitor/keyboard": "1.0.2",
    "@capacitor/status-bar": "1.0.2",
    "@ionic/angular": "^5.5.2",
    "@nativescript/capacitor": "^1.0.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.0.1",
    "@angular-eslint/builder": "~12.0.0",
    "@angular-eslint/eslint-plugin": "~12.0.0",
    "@angular-eslint/eslint-plugin-template": "~12.0.0",
    "@angular-eslint/template-parser": "~12.0.0",
    "@angular/cli": "~12.0.1",
    "@angular/compiler": "~12.0.1",
    "@angular/compiler-cli": "~12.0.1",
    "@angular/language-service": "~12.0.1",
    "@capacitor/cli": "3.1.1",
    "@ionic/angular-toolkit": "^4.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "4.16.1",
    "@typescript-eslint/parser": "4.16.1",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.7.1",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.2.4"
  },
  "description": "An Ionic project"
}

Problem

I've created fresh project following exact steps from: https://capacitor.nativescript.org/installation.html (except: I've generated blank application instead of tabs). Everything went flawlessly except native functions aren't getting called. I've been cleaning project and Android Studio, updating nativescript and capacitor dependencies and also playing around with gradle version, but in the end that didn't affect anything. I've followed guide twice ensuring calling npm i @nativescript/capacitor after npx cap add android.

home.page.ts

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor() {}

  async doStuff() {
    console.log(`START!`);
    const brightness = Math.round(Math.random() * 100);
    console.log(`SET BRIGHTNESS TO!`, brightness);
    native.setScreenBrightness(brightness);
    native.openNativeModalView();

    console.log(1, native.isAndroid);

    console.log(`END!`);
  }

}

After activating action: image

There are a lot of events sent to NativeScriptCap.notify when I activate that function, but even simplest native.isAndroid returns undefined, brightness isn't changed and modal isn't opening. Code for brightness and modal are copy-pasted from documentation and imported in nativescript/index.ts.

NathanWalker commented 3 years ago

@radarsu what Android Studio version do you have installed, and can you see what gradle version is installed? Guess also good to collect node/npm version while we can.

Also would it be possible to post that project on github and share a link; we could take a look to see if something jumps out?