我正在尝试在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
如何解决我的问题? 非常感谢你的帮助。
答案 0 :(得分:2)
最后解决了在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
答案 1 :(得分:0)
我认为您只需要在应用程序的build.gradle文件的依赖项部分添加以下内容:
dependencies
{
compile "com.google.android.gms:play-services-gcm:9.0.0"
}
来源: https://developers.google.com/cloud-messaging/android/client