Gradle "com.android.dex.DexException" 构建一个涉及 cordova-plugin-googlemaps 和 ibm-mfp-push 插件的应
Posted
技术标签:
【中文标题】Gradle "com.android.dex.DexException" 构建一个涉及 cordova-plugin-googlemaps 和 ibm-mfp-push 插件的应用程序。【英文标题】:Gradle "com.android.dex.DexException" building an app involving cordova-plugin-googlemaps and ibm-mfp-push plugins. 【发布时间】:2016-07-03 10:13:32 【问题描述】:我正在尝试在 android 平台上构建一个 Ionic 应用程序,包括 ibm-mfp-push cordova pplugin 和 googlemaps cordova 插件。
从一个全新的 Ionic 应用程序开始,我首先导入了 cordova ibm-mfp-push 插件,并且 android 构建成功完成。
导入cordova-plugin-googlemaps
后,gradle 构建中断并出现以下(常见)异常:
:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzqm;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
按照常用方法,我在我的依赖树中查找所有导致冲突的模块:
[...]
compile - Classpath for compiling the main sources.
+--- com.ibm.mobilefirstplatform.clientsdk.android:core:1.+ -> 1.2.2
| \--- com.squareup.okhttp:okhttp:2.4.0
| \--- com.squareup.okio:okio:1.4.0
+--- com.ibm.mobilefirstplatform.clientsdk.android:push:1.+ -> 1.0.2
| +--- com.android.support:appcompat-v7:23.0.0
| | \--- com.android.support:support-v4:23.0.0
| | \--- com.android.support:support-annotations:23.0.0
| +--- com.ibm.mobilefirstplatform.clientsdk.android:core:1.1.0 -> 1.2.2 (*)
| \--- com.google.android.gms:play-services:7.8.0
| +--- com.google.android.gms:play-services-ads:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0
| | | +--- com.google.android.gms:play-services-basement:9.2.0
| | | | \--- com.android.support:support-v4:23.0.0 (*)
| | | \--- com.google.android.gms:play-services-tasks:9.2.0
| | | \--- com.google.android.gms:play-services-basement:9.2.0 (*)
| | +--- com.google.android.gms:play-services-analytics:7.8.0
| | | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| | \--- com.google.android.gms:play-services-appindexing:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-analytics:7.8.0 (*)
| +--- com.google.android.gms:play-services-appindexing:7.8.0 (*)
| +--- com.google.android.gms:play-services-appinvite:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-appstate:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-cast:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| | \--- com.android.support:mediarouter-v7:22.2.0
| | \--- com.android.support:appcompat-v7:22.2.0 -> 23.0.0 (*)
| +--- com.google.android.gms:play-services-drive:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-fitness:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| | \--- com.google.android.gms:play-services-location:7.8.0 -> 9.2.0
| | +--- com.google.android.gms:play-services-base:9.2.0 (*)
| | \--- com.google.android.gms:play-services-basement:9.2.0 (*)
| +--- com.google.android.gms:play-services-games:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| | \--- com.google.android.gms:play-services-drive:7.8.0 (*)
| +--- com.google.android.gms:play-services-gcm:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-identity:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-location:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-maps:7.8.0 -> 9.2.0
| | +--- com.google.android.gms:play-services-base:9.2.0 (*)
| | \--- com.google.android.gms:play-services-basement:9.2.0 (*)
| +--- com.google.android.gms:play-services-nearby:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-panorama:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-plus:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-safetynet:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-vision:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| +--- com.google.android.gms:play-services-wallet:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
| | +--- com.google.android.gms:play-services-identity:7.8.0 (*)
| | \--- com.google.android.gms:play-services-maps:7.8.0 -> 9.2.0 (*)
| \--- com.google.android.gms:play-services-wearable:7.8.0
| \--- com.google.android.gms:play-services-base:7.8.0 -> 9.2.0 (*)
+--- com.google.android.gms:play-services-maps:+ -> 9.2.0 (*)
\--- com.google.android.gms:play-services-location:+ -> 9.2.0 (*)
[...]
最后我排除了以下模块:
configurations
all*.exclude group: 'com.google.android.gms', module: 'play-services-analytics'
all*.exclude group: 'com.google.android.gms', module: 'play-services-appindexing'
all*.exclude group: 'com.google.android.gms', module: 'play-services-ads'
all*.exclude group: 'com.google.android.gms', module: 'play-services-gcm'
all*.exclude group: 'com.google.android.gms', module: 'play-services-plus'
all*.exclude group: 'com.google.android.gms', module: 'play-services-safetynet'
all*.exclude group: 'com.google.android.gms', module: 'play-services-wallet'
all*.exclude group: 'com.google.android.gms', module: 'play-services-wearable'
现在,构建成功终止,但运行时出现 ClassNotFoundException:
E/AndroidRuntime(17337): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(17337): at android.os.AsyncTask$3.done(AsyncTask.java:305)
E/AndroidRuntime(17337): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
E/AndroidRuntime(17337): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
E/AndroidRuntime(17337): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(17337): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:232)
E/AndroidRuntime(17337): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(17337): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(17337): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(17337): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/gcm/GoogleCloudMessaging;
E/AndroidRuntime(17337): at com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush$6.doInBackground(MFPPush.java:547)
E/AndroidRuntime(17337): at com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush$6.doInBackground(MFPPush.java:541)
E/AndroidRuntime(17337): at android.os.AsyncTask$2.call(AsyncTask.java:293)
E/AndroidRuntime(17337): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime(17337): ... 4 more
E/AndroidRuntime(17337): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.gcm.GoogleCloudMessaging" on path: DexPathList[[zip file "/data/app/com.dsg.Smokers-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(17337): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(17337): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(17337): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(17337): ... 8 more
E/AndroidRuntime(17337): Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.gcm.GoogleCloudMessaging
E/AndroidRuntime(17337): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(17337): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(17337): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(17337): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(17337): ... 9 more
E/AndroidRuntime(17337): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
如何解决我的问题? 非常感谢您的帮助。
【问题讨论】:
【参考方案1】:终于解决了在Android项目中修改project.properties
文件,改下面几行
cordova.system.library.1=com.google.android.gms:play-services-maps:9.2.0
cordova.system.library.2=com.google.android.gms:play-services-location:9.2.0
以下内容:
cordova.system.library.1=com.google.android.gms:play-services-maps:7.8.0
cordova.system.library.2=com.google.android.gms:play-services-location:7.8.0
【讨论】:
【参考方案2】:我认为您只需要在应用程序的 build.gradle 文件的依赖项部分添加以下内容:
dependencies
compile "com.google.android.gms:play-services-gcm:9.0.0"
来源: https://developers.google.com/cloud-messaging/android/client
【讨论】:
以上是关于Gradle "com.android.dex.DexException" 构建一个涉及 cordova-plugin-googlemaps 和 ibm-mfp-push 插件的应的主要内容,如果未能解决你的问题,请参考以下文章
离子摇篮失败“找不到 com.android.tools.build:gradle:2.2.3”
升级到 Gradle 6 和 Android Gradle 插件 4.0.0 无法获取“https://dl.google.com/android/repository/addons_list-3.x
Android Studio 中build.gradle文件的详细解析
无法在 app/build.gradle 中在线导入 com.android.build.OutputFile 解析符号“build”