insightautos / cordova-gmv-barcode-scanner

A Cordova barcode scanning plugin based on the Google Mobile Vision library for iOS & Android.
MIT License
52 stars 77 forks source link

Error initializing Cordova: Class not found #5

Closed chun-baoluo closed 6 years ago

chun-baoluo commented 6 years ago

Hi! Really cool plugin you have here, helped me a lot. However, I encountered a specific error in my app after installing it on android devices (my current platform is cordova-android@7.0.0) - Error initializing Cordova: Class not found. And I found out why - this plugin removed all feature tags in app/src/main/res/xml/config.xml except feature tag related to the plugin itself, the reason being incorrect structure created in platforms/android/android.json. Apparently, in android.json both res/xml/config.xml (created by other plugins) and app/src/main/res/xml/config.xml (created by this plugin) properties were present and Cordova used only the latter when it generated config.xml for Android platform. I managed to fix this error by removing config-file target="app/src/main/res/xml/config.xml" and leaving only config-file target="res/xml/config.xml" in plugin.xml. After this fixes, my app was able to launch successfully.

Also, I encountered another bug on my Xiaomi smartphone (Android 7.0) - the app created a shortcut called "Barcode Reader Sample" after installation. Any attempts to remove the shortcut caused the app to uninstall together with it. I fixed this as well, by replacing android.intent.category.LAUNCHER with android.intent.category.DEFAULT in an activity tag in plugin.xml.

I created a pull request with the fixes I mentioned - #4.

chun-baoluo commented 6 years ago

Seems like you left only app/src/main-like tags in recent commits. The error still appears in my app. Only the usual res/xml/config.xml path for config-file tag fixed this error for me yet again.

forrestmid commented 6 years ago

Hey Pavel, I’m glad someone else found this plugin useful as well! Could you try installing cordova-android@7.1.0? It doesn’t appear there are any breaking changes in that as far as Cordova goes and the app/src/main path is the only thing that works for me in later versions. My attempt with putting both paths in was to get the app to work on any cordova-android version, but clearly that didn’t work. We may need to constrain the installbase to cordova-android@7.1.0 and up if that is the case. Did you have any issues with the AndroidManifest being edited at multiple files? What doesn’t make sense to me is that the phone gap push plugin seems to not reference the correct path and yet people still install it. I wonder if there’s some development bug specific to me causing the app/src/main path to be the only one that works and other people don’t have that issue. I’ll try to take a look at the intent issue as well. I don’t have an android device so I’m limited to the simulator. On Wed, Aug 1, 2018 at 2:21 AM, Pavel Bakharev notifications@github.com wrote: Seems like you left only app/src/main -like tags in recent commits. The error still appears in my app. Only the usual res/xml/config.xml path for config-file tag fixes this error for me.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub [https://github.com/dealrinc/cordova-gmv-barcode-scanner/issues/5#issuecomment-409492172] , or mute the thread [https://github.com/notifications/unsubscribe-auth/AHvidfLwIHyxw_ASLChyp0pnNT41vvgKks5uMWTwgaJpZM4VqCTa] .

chun-baoluo commented 6 years ago

Could you try installing cordova-android@7.1.0?

No, bumping cordova-android to version 7.1.0 didn't help me. I still get Class not found error.

Did you have any issues with the AndroidManifest being edited at multiple files?

Do you mean two config-file tags with two different paths for AndroidManifest file? No, everything seemed to work fine with both of them and I didn't delete any in plugin.xml. Only app/src/main path for config.xml caused problems.

What doesn’t make sense to me is that the phone gap push plugin seems to not reference the correct path and yet people still install it.

Yeah, I encountered app/src/main paths for config.xml in some plugins as well, but majority still use just res/xml/config.xml path. For example, firebase-config plugin (which I also use in my app) works only with cordova-android >= 7.0.0 and it uses old-fashioned path for the config file.

https://github.com/chemerisuk/cordova-plugin-firebase-config/blob/master/plugin.xml

forrestmid commented 6 years ago

Very interesting. Thanks for that information.

I ended up switching the config.xml path to the default path, as you suggested and kept the AndroidManifest.xml path with two separate entries. I verified that the plugin works in the sample app both with cordova-android@6.4 and cordova-android@7.1 so the app in the latest version should work appropriately.

I believe that for the application I developed the plugin for I will have to make my own fork since I wasn't able to get it to run without the app/src/main path on the config.xml. Perhaps that info will help someone in the future!

Thanks for contributing!

forrestmid commented 6 years ago

I would also appreciate it if you could try out the latest plugin version in your app to verify it works in the real world! Thanks!

chun-baoluo commented 6 years ago

Cool! The error doesn't appear anymore and my app launches without a hitch. However, Barcode Reader Sample shortcut still does appear on my Xiaomi smartphone. I created a new pull request with the fix for this bug: #6.

markdesigner commented 4 years ago

Hello guys, when I clone the cordova project from remote, and run 'cordova platform add ios', everything is all right but come out "Failed to install 'cordova-gmv-barcode-scanner': undefined" is their someone have good advice? thank you very much. we use barcode pluging in out project, I see 'cordova-gmv-barcode-scanner' folder in plugin, but still wrong~ this will ends up Xcode build fail