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

[Bug report] Error when starting the scan #724

Closed
ctaddei opened this issue Aug 30, 2023 · 17 comments
Closed

[Bug report] Error when starting the scan #724

ctaddei opened this issue Aug 30, 2023 · 17 comments

Comments

@ctaddei
Copy link

ctaddei commented Aug 30, 2023

Describe the bug
When calling startScan() in barcode-scanning-modal.component.ts i'm getting a "startScan failed", it opens the dialog with the interface, but its all black, camera is not starting.

ERROR:

s```
tartScan failed.
java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference
at io.capawesome.capacitorjs.plugins.mlkit.barcodescanning.BarcodeScanner.lambda$startScan$0(BarcodeScanner.java:108)
at io.capawesome.capacitorjs.plugins.mlkit.barcodescanning.BarcodeScanner.$r8$lambda$XoJ4tltbmXkBZjUvzn_RkQLTSis(Unknown Source:0)
at io.capawesome.capacitorjs.plugins.mlkit.barcodescanning.BarcodeScanner$$ExternalSyntheticLambda3.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
2023-08-30 11:20:50.876 27835-27835 Capacitor io.ionic.starter D Sending plugin error: {"save":false,"callbackId":"35338673","pluginId":"BarcodeScanner","methodName":"startScan","success":false,"error":{"message":"Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference"}}
2023-08-30 11:20:50.883 27835-27835 Capacitor/Console io.ionic.starter E File: https://localhost/main.8d0c386ac6862cd3.js - Line 1 - Msg: ERROR Error: Uncaught (in promise): Error: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference
Error: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference
at returnResult (https://localhost/:768:32)
at win.androidBridge.onmessage (https://localhost/:743:21)



**Expected behavior**
I want to start the camera to scan a barcode

**SDK Info:**
Android 9 (pie)

**Smartphone:**
 Samsung A12

@ctaddei ctaddei closed this as completed Aug 31, 2023
@ctaddei
Copy link
Author

ctaddei commented Aug 31, 2023

Made it start, now i'm getting an "Android chroma siting range" error

@christopherblackza
Copy link

@ctaddei What did you do to make it start? I'm stuck with the error -
Error: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference
Error: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference

If I update capacitor versions I get error -
MLKit Barcode Scanner Module not installed? Do you know anything about this?

@massivespace
Copy link

@ctaddei we are running into this same issue. Do you mind sharing how you fixed it?

@Lange87
Copy link

Lange87 commented Sep 13, 2023

I'm getting the same error. Can you share how you fixed it?

@PaoloDeLux
Copy link

Same trouble

@cneuburger
Copy link

also same issue

@Lange87
Copy link

Lange87 commented Oct 4, 2023

I fixed it by removing @capacitor-community/firebase-analytics plugin. When I removed it, the barcode scanner is working.

@Melynt3
Copy link

Melynt3 commented Oct 5, 2023

Well, i got same error and im not using firebase-analytics 🤔 Anyone solved it in different way?

@lionflence
Copy link

For everyone using capacitor and the barcode scanner plugin coming from google, this solved the issue for me:

capawesome-team/capacitor-mlkit#53 (comment)

The order of the plugins added to capacitor.build.gradle seems to be the problem and adding the code from rdlabo to capacitor.config.json solved the issue for me.

@jchri853
Copy link

Anyone using biometric plugins? I am setting barcode scanning first and still encounter the problem.

Removing capgo-capacitor-native-biometric resolves the issue.

dependencies {
    implementation project(':capacitor-mlkit-barcode-scanning')
    implementation project(':capacitor-app')
    implementation project(':capacitor-browser')
    implementation project(':capacitor-device')
    implementation project(':capacitor-geolocation')
    implementation project(':capacitor-haptics')
    implementation project(':capacitor-keyboard')
    implementation project(':capacitor-push-notifications')
    implementation project(':capacitor-splash-screen')
    implementation project(':capacitor-status-bar')
    implementation project(':capgo-capacitor-native-biometric')
}

@nicofzzn
Copy link

same issue here

capacitor.config.ts
android: { includePlugins: [ '@capacitor-mlkit/barcode-scanning', '@capacitor-community/photoviewer', '@capacitor/app', '@capacitor/camera', '@capacitor/dialog', '@capacitor/geolocation', '@capacitor/haptics', '@capacitor/keyboard', '@capacitor/push-notifications', '@capacitor/status-bar' ] }

removing @capacitor-community/photoviewer will work, but i need both plugin

@jovicailievski
Copy link

Hello, the issue is that plugin has to be imported first in the dependencies of the capacitor.build.gradle so to do that you need to make sure that in you package.json file under dependencies first imported plugin is this one (like in the image) and then it will always be automatically put first in the capacitor.build.gradle. When you change it as first just do npm install, npx cap sync and just rebuild the native project.
image

@jchri853
Copy link

jchri853 commented Nov 22, 2023

Package.json

       "@capacitor-mlkit/barcode-scanning": "5.0.1",
        "@capacitor/android": "^5.2.3",
        "@capacitor/app": "^5.0.6",
        "@capacitor/browser": "^5.0.6",
        "@capacitor/core": "^5.2.3",
        "@capacitor/device": "^5.0.6",
        "@capacitor/geolocation": "^5.0.6",
        "@capacitor/haptics": "^5.0.6",
        "@capacitor/ios": "^5.2.3",
        "@capacitor/keyboard": "^5.0.6",
        "@capacitor/push-notifications": "^5.0.6",
        "@capacitor/splash-screen": "^5.0.6",
        "@capacitor/status-bar": "^5.0.6",
        "@capgo/capacitor-native-biometric": "^5.0.1",

dependancies

dependencies {
    implementation project(':capacitor-mlkit-barcode-scanning')
    implementation project(':capacitor-app')
    implementation project(':capacitor-browser')
    implementation project(':capacitor-device')
    implementation project(':capacitor-geolocation')
    implementation project(':capacitor-haptics')
    implementation project(':capacitor-keyboard')
    implementation project(':capacitor-push-notifications')
    implementation project(':capacitor-splash-screen')
    implementation project(':capacitor-status-bar')
    implementation project(':capgo-capacitor-native-biometric')
}
     

It looks like we both did that and are still seeing the problem

@garzon-it
Copy link

Was anyone able to solve this issue? I am having the same problem:

Error: "Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference"

The problem I have is a conflict with the "@capacitor-community/photoviewer" plugin. If I remove that Plugin it works, but I need both.

@Roshwin
Copy link

Roshwin commented Feb 23, 2024

@jchri853 Thank you for your response, it helped me resolve my issue but i had to run "npx cap sync" and "ionic build".
If i only build, then it would revert to dependencies and order.
After running sync then build in the same order as your response, it now works perfectly

@TheCorbin
Copy link

Why is this closed and how was it fixed?! I'm still having issues with the biometric plugin and this package.

@shiehnpin
Copy link

@TheCorbin Not sure this workaround would fix your problem, but it is worth to try:

Add/Update your bridge_layout_main.xml in your app module (e.g. /android/app/src/main/res/layout/bridge_layout_main.xml) with this to override the bridge_layout_main.xml. You might need to import androidx.camera library in build.gradle as well.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.getcapacitor.BridgeActivity">

    <androidx.camera.view.PreviewView
        android:id="@+id/preview_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
        
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

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