我的应用程序应该使用相机扫描条形码,如果用户使用TC55 Motorola设备,则使用内置扫描仪。为了使其工作,我必须在build.gradle文件中指定:
dependencies {
provided files('libs/com.symbol.emdk.jar')
但是,如果我在非TC55设备上使用此行运行apk,则应用程序将崩溃。
如何创建在TC55和非TC55设备上均可使用的单一 flavor 版本?
编辑1:
AndroidRuntime: FATAL EXCEPTION: main
Process: company.mobile.application.app, PID: 28701
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{company.mobile.application.app/com.company.mobile.application.ui.Pr oductionActivity}: java.lang.ClassNotFoundException: Didn't find class "com.company.mobile.application.ui.ProductionActivity" on path: DexPathList[[zip file "/data/app/company.mobile.application.app-3.apk"],nativeLibraryDirectories= [/data/app-lib/company.mobile.application.app-3, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.company.mobile.application.ui.ProductionActivity" on path: DexPathList[[zip file "/data/app/company.mobile.application.app-3.apk"],nativeLibraryDirectories= [/data/app-lib/company.mobile.application.app-3, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
要在TC55上使用Zebra的EMDK,您需要使用EMDK库,该库仅在TC55等Zebra设备上可用。
因此,如果您尝试打开一个实现EMDK接口(interface)之一(EMDKListener,DataListener或StatusListener)的Activity,则当EMDK不可用时,应用程序将崩溃。
因此,从AndroidManifest.xml
开始,您需要考虑EMDK库在设备上可能不可用:
<uses-library android:name="com.symbol.emdk" android:required="false" />
关键点是:不要在您的主Activity中实现EMDK的监听器之一,否则当您在非Zebra设备上运行(缺少所需的EMDK库)时,您的应用将崩溃。
您可以看看this sample application,它在使第二个 Activity (基于EMDK侦听器)可用之前检查EMDK是否可用。