Skip to content

@nativescript/core 8.5.4+: ReferenceError androidApp is not defined #10323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
felixkrautschuk opened this issue Jun 23, 2023 · 3 comments · Fixed by #10324
Closed
3 tasks done

@nativescript/core 8.5.4+: ReferenceError androidApp is not defined #10323

felixkrautschuk opened this issue Jun 23, 2023 · 3 comments · Fixed by #10324
Labels

Comments

@felixkrautschuk
Copy link
Contributor

Issue Description

After upgrading @nativescript/core from 8.5.3 to 8.5.4 (or latest 8.5.6), our Android app is crashing for Android 8 and below when calling the connectivity startMonitoring method.

//app.js

const applicationModule = require("@nativescript/core/application");
const connectivityModule = require("@nativescript/core/connectivity");

applicationModule.on(applicationModule.suspendEvent, function(args) {
  connectivityModule.stopMonitoring();
});


applicationModule.on(applicationModule.resumeEvent, function(args) {
  connectivityModule.startMonitoring(function(newConnectionType) {
    console.log(newConnectionType);
  });
});

applicationModule.run({ moduleName: 'app-root' });

Reproduction

app for reproduction:
nsandroidcrash.zip

Just start the app on Android 8 or below, then you will see the crash.

Relevant log output (if applicable)

System.err: java.lang.RuntimeException: Unable to resume activity {org.nativescript.nsandroidcrash/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onPostResume failed
  System.err: ReferenceError: androidApp is not defined
  System.err:   at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3429)
  System.err:   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3469)
  System.err:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732)
  System.err:   at android.app.ActivityThread.-wrap12(ActivityThread.java)
  System.err:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
  System.err:   at android.os.Handler.dispatchMessage(Handler.java:102)
  System.err:   at android.os.Looper.loop(Looper.java:154)
  System.err:   at android.app.ActivityThread.main(ActivityThread.java:6119)
  System.err:   at java.lang.reflect.Method.invoke(Native Method)
  System.err:   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  System.err:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  System.err: Caused by: com.tns.NativeScriptException: Calling js method onPostResume failed

Environment

OS: macOS 13.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Shell: /bin/zsh
node: 16.17.0
npm: 8.19.3
nativescript: 8.5.3

# android
java: 11.0.11
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 14.3.1/14E300c
cocoapods: 1.12.1
python: 2.7.18
python3: 3.9.6
ruby: 2.6.10
platforms: 
  - DriverKit 22.4
  - iOS 16.4
  - macOS 13.3
  - tvOS 16.4
  - watchOS 9.4

Dependencies

"dependencies": {
  "@nativescript/core": "^8.5.6"
},
"devDependencies": {
  "@nativescript/android": "8.5.0",
  "@nativescript/webpack": "^5.0.16"
}

Please accept these terms

@felixkrautschuk felixkrautschuk added the bug-pending-triage Reported bug, pending triage to confirm. label Jun 23, 2023
@rigor789
Copy link
Member

rigor789 commented Jun 23, 2023

The attached app runs without errors for me, only changed the console.log to add the "Connection type changed" string at the start to make it easier to see in the output.

const applicationModule = require("@nativescript/core/application");
const connectivityModule = require("@nativescript/core/connectivity");

applicationModule.on(applicationModule.suspendEvent, function(args) {
  connectivityModule.stopMonitoring();
});


applicationModule.on(applicationModule.resumeEvent, function(args) {
  connectivityModule.startMonitoring(function(newConnectionType) {
    console.log('Connection type changed', newConnectionType);
  });
});

applicationModule.run({ moduleName: 'app-root' });
Webpack compilation complete. Watching for file changes.
Successfully transferred bundle.js on device emulator-5554.
Restarting application on device emulator-5554...
+ Connection type changed 1
device: emulator-5554 debug port: 40000

To start debugging, open the following URL in Chrome:
devtools://devtools/bundled/inspector.html?ws=localhost:40000

Successfully synced application org.nativescript.nsandroidcrash on device emulator-5554.

Do note that deep imports into the application are deprecated, so the recommended way to write this would be:

import { Application, Connectivity } from "@nativescript/core";

Application.on(Application.suspendEvent, () => {
  Connectivity.stopMonitoring();
})

Application.on(Application.resumeEvent, () => {
  Connectivity.startMonitoring((newConnectionType) => {
    console.log('Connection type changed', newConnectionType);
  });
});

Application.run({ moduleName: 'app-root' });

@rigor789 rigor789 added needs more info and removed bug-pending-triage Reported bug, pending triage to confirm. labels Jun 23, 2023
@rigor789
Copy link
Member

Edit: Sorry, I missed the android 8 or below part - let me run that.

@felixkrautschuk
Copy link
Contributor Author

Now it's working, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants