Skip to content
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

Crashes Android app on NS8 #269

Open
delanick opened this issue Jun 30, 2021 · 7 comments
Open

Crashes Android app on NS8 #269

delanick opened this issue Jun 30, 2021 · 7 comments

Comments

@delanick
Copy link

Hi @EddyVerbruggen

Since moving to NS8, this plugin crashes the Android version of my app. Works perfectly fine on iOS. Errors received are:

System.err: An uncaught Exception occurred on "main" thread. System.err: Calling js method onViewAttachedToWindow failed System.err: TypeError: activity.getLifecycle is not a function System.err: System.err: StackTrace: System.err: _onAttachedToWindow(file: app/webpack:/wesignit/node_modules/@nativescript-community/ui-material-bottom-navigation/index.android.js:307:0) System.err: at AttachListener.onViewAttachedToWindow(file: app/webpack:/wesignit/node_modules/@nativescript-community/ui-material-bottom-navigation/index.android.js:157:0) System.err: at com.tns.Runtime.callJSMethodNative(Native Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302) System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1175) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1153) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1149) System.err: at com.tns.gen.java.lang.Object_vendor_177_28_AttachListener.onViewAttachedToWindow(Object_vendor_177_28_AttachListener.java:18) System.err: at android.view.View.dispatchAttachedToWindow(View.java:18637) System.err: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3520) System.err: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3527) System.err: at android.view.ViewGroup.addViewInner(ViewGroup.java:5162) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4953) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4893) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4866) System.err: at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:205) System.err: at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72) System.err: at androidx.transition.ViewGroupOverlayApi18.add(ViewGroupOverlayApi18.java:48) System.err: at androidx.transition.Visibility.onDisappear(Visibility.java:428) System.err: at androidx.transition.Visibility.createAnimator(Visibility.java:257) System.err: at androidx.transition.Transition.createAnimators(Transition.java:747) System.err: at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480) System.err: at androidx.transition.Transition.playTransition(Transition.java:1821) System.err: at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:301) System.err: at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1045) System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2813) System.err: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1785) System.err: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7832) System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:723) System.err: at android.view.Choreographer.doFrame(Choreographer.java:658) System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) System.err: at android.os.Handler.handleCallback(Handler.java:789) System.err: at android.os.Handler.dispatchMessage(Handler.java:98) System.err: at android.os.Looper.loop(Looper.java:164) System.err: at android.app.ActivityThread.main(ActivityThread.java:6944) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

I don't know what any of that means and thus not able to fix it.

My package.json looks as follows:

"dependencies": { "@nativescript-community/ui-material-bottom-navigation": "^5.3.5", "@nativescript/core": "~8.0.0", "@nativescript/social-share": "^2.0.4", "@nativescript/theme": "~3.0.1", "@nstudio/nativescript-exoplayer": "^5.0.6", "nativescript-appversion": "^1.4.4", "nativescript-barcodescanner": "^4.1.1", "nativescript-bottom-navigation": "^2.0.5", "nativescript-iqkeyboardmanager": "^1.5.1", "nativescript-material-icons": "^1.0.3", "nativescript-pushy": "^2.1.0" }, "devDependencies": { "@nativescript/android": "8.0.0", "@nativescript/ios": "8.0.0", "@nativescript/types": "8.0.0", "@nativescript/webpack": "~5.0.0-beta.0", "eslint": "~7.7.0", "node-sass": "^4.14.1"

@rob4226
Copy link

rob4226 commented Jul 11, 2021

Hi @EddyVerbruggen thank you for this great plugin! I am unfortunately having the same issue since moving to NativeScript 8 on Android. As soon as the camera opens the app crashes:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onViewAttachedToWindow failed
System.err: TypeError: activity.getLifecycle is not a function
System.err:
System.err: StackTrace:
System.err: _onAttachedToWindow(file: src\webpack:\mobile\node_modules\@nativescript-community\ui-material-bottom-navigation\index.android.js:307:0)
System.err:     at AttachListener.onViewAttachedToWindow(file: src\webpack:\mobile\node_modules\@nativescript-community\ui-material-bottom-navigation\index.android.js:157:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.java.lang.Object_vendor_576_28_AttachListener.onViewAttachedToWindow(Object_vendor_576_28_AttachListener.java:18)
System.err:     at android.view.View.dispatchAttachedToWindow(View.java:18418)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3407)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3414)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3414)
System.err:     at android.view.ViewGroup.addViewInner(ViewGroup.java:5091)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4879)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4819)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4792)
System.err:     at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:205)
System.err:     at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
System.err:     at androidx.transition.ViewGroupOverlayApi18.add(ViewGroupOverlayApi18.java:48)
System.err:     at androidx.transition.Visibility.onDisappear(Visibility.java:428)
System.err:     at androidx.transition.Visibility.createAnimator(Visibility.java:257)
System.err:     at androidx.transition.Transition.createAnimators(Transition.java:747)
System.err:     at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
System.err:     at androidx.transition.Transition.playTransition(Transition.java:1821)
System.err:     at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:301)
System.err:     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
System.err:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2502)
System.err:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1479)
System.err:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7211)
System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:761)
System.err:     at android.view.Choreographer.doFrame(Choreographer.java:696)
System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
System.err:     at android.os.Handler.handleCallback(Handler.java:873)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:193)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6880)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@delanick
Copy link
Author

@rob4226 Have you found a solution to this yet?

Not sure if @EddyVerbruggen is still maintaining this repo or not.

@rob4226
Copy link

rob4226 commented Jul 19, 2021

@delanick I found that it is caused by some interaction between this barcode-scanner plugin and the @nativescript-community/ui-material-bottom-navigation plugin. Specifically, the error occurs when activity.getLifecycle() is called:

https://github.com/nativescript-community/ui-material-components/blob/2140ffc99ffe3ab1eef87ef8c8852e644c271b5b/src/bottom-navigation/index.android.ts#L400-L417

I am not sure what the exact problem is, or why it happens, but as a hack I added a check for the getLifecycle() function before calling it, which seems to have allowed everything to work. I changed lines 406 - 408 to:

if ((this._manager && this._manager.isDestroyed()) ||  (activity.hasOwnProperty('getLifecycle') && !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED))) {
  return;
}

Note the addtional activity.hasOwnProperty('getLifecycle') && check. Although this makes it work, I don't know if it is the proper solution for it. Any idea's anyone??

@delanick
Copy link
Author

@rob4226 that's awesome that you found a hack, well done and thank you for sharing! Which file do I make those changes on?

@rob4226
Copy link

rob4226 commented Jul 19, 2021

@delanick Np, I hope it works for you. We should probably follow up on this in the bottom-drawer plugin repo so maybe they can address it.

The file is located in the bottom-navigation plugin so in your project: node_modules/@nativescript-community/ui-material-bottom-navigation/index.android.js

You can try it first there to make sure it works for you but if it does, you are probably better off cloning that repo, then making the change in src/bottom-navigation/index.android.ts and building the plugin, then install it locally in your project so the change will be permanent. Otherwise, every time you run npm install for you project, your changes in your node_modules will be overwritten.

@delanick
Copy link
Author

@rob4226 thanks so much, got it working. My file was different to yours as I have bottom nav installed separately. But it works, which is what matters.

As for your other point, yep, exactly that - will need to clone and build the plugin myself. Issue is, I'm a noob when it comes to plugins, so have no idea how to build it. Any advice?

@timdoege
Copy link

timdoege commented Dec 1, 2021

You can
Clone the project

cd NativeScript/plugins
git clone [email protected]:EddyVerbruggen/nativescript-barcodescanner.git
cd nativescript-barcodescanner
-- Optional: apply PR 278 to prevent iOS full screen crashes - requires Github CLI --
gh pr checkout 278
cd src
-- change version to 4.1.3 in package.json --
npm run build                                                         
cd publish
./pack.sh
mv package/nativescript-barcodescanner-4.1.3.tgz ~/my-app-folder/plugins

Update package.jsonto use local file

"nativescript-barcodescanner": "file:plugins/nativescript-barcodescanner-4.1.3.tgz",

and run

ns clean
npm i

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

No branches or pull requests

3 participants