Phonegap-plugin-barcodescanner: Can't install the plugin on ionic

Created on 5 Apr 2019  路  9Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

Expected Behaviour

Barcode scanner to load

Actual Behaviour

Crashes with the error

android.content.ActivityNotFoundException: Unable to find explicit activity class {io.ionic.starter/com.google.zxing.client.android.CaptureActivity}; have you declared this activity in your AndroidManifest.xml?

Similar to #640

Reproduce Scenario (including but not limited to)

Install plugin on Ionic and start the app

Steps to Reproduce

$ phonegap plugin add phonegap-plugin-barcodescanner

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

AVD Emulator, Android 9.0 (API 28)

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Nexus 5X from Android Studio

Cordova CLI version and cordova platform version

$ cordova --version
9.0.0
$ cordova platforms
Installed platforms:
  android 8.0.0
  browser 6.0.0

Plugin version

phonegap-plugin-barcodescanner 8.0.1 "BarcodeScanner"

Sample Code that illustrates the problem

Generated android manifest

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera" android:required="true" />
</manifest>

Logs taken while reproducing problem

D/CordovaActivity: Incoming Result. Request code = 47740
D/CordovaInterfaceImpl: Sending activity result to plugin

--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2
    Process: io.ionic.starter, PID: 3063
    android.content.ActivityNotFoundException: Unable to find explicit activity class {io.ionic.starter/com.google.zxing.client.android.CaptureActivity}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4586)
        at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:343)
        at android.app.Activity.startActivityForResult(Activity.java:4544)
        at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:68)
        at com.phonegap.plugins.barcodescanner.BarcodeScanner$1.run(BarcodeScanner.java:204)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
stale

Most helpful comment

To make this work I had to add this to my config.xml file:

<config-file parent="/manifest/application" target="AndroidManifest.xml">
     <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
         <intent-filter>
             <action android:name="com.phonegap.plugins.barcodescanner.SCAN" />
             <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
     </activity>
</config-file>

I've taken these lines from the old Android repo

All 9 comments

On ionic 4 you can install it using ionic cordova plugin add phonegap-plugin-barcodescanner && npm install @ionic-native/barcode-scanner, see the ionic docs: https://ionicframework.com/docs/native/barcode-scanner/

Hello, @math-98
Do you have some kind of progress or workaround by now? I am facing a similar issue.
See #793 for more info.

To make this work I had to add this to my config.xml file:

<config-file parent="/manifest/application" target="AndroidManifest.xml">
     <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
         <intent-filter>
             <action android:name="com.phonegap.plugins.barcodescanner.SCAN" />
             <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
     </activity>
</config-file>

I've taken these lines from the old Android repo

Thank you for your response. Unfortunately after adding your code to config.xml I get a new error.
Element activity#com.google.zxing.client.android.CaptureActivity at AndroidManifest.xml:19:9-24:20 duplicated with element declared at AndroidManifest.xml:13:9-311
It seems I have this line of code. Yet the plugin is still not working.

I managed to it work as well.
Reference #793.

To make this work I had to add this to my config.xml file:

<config-file parent="/manifest/application" target="AndroidManifest.xml">
     <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
         <intent-filter>
             <action android:name="com.phonegap.plugins.barcodescanner.SCAN" />
             <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
     </activity>
</config-file>

I've taken these lines from the old Android repo

Thanks. works like a charm

I tried the above, didn't work. So I just did the old remove android platform then re-add it:

ionic cordova platform remove android
ionic cordova platform add android

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings