android-MultiDex问题-任务’:app:dexDebug’的执行失败
作者:互联网
在为Google Calendar API添加一行以build.gradle时遇到问题.这是错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]:65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/usr/java/jdk1.7.0_79/bin/java''
finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 14.802 secs
Information:1 error
Information:2 warnings
Information:See complete output in console
我尝试了很多选择,但没有任何效果.当我向defaultConfig添加“ multiDex true”时,appcompat库无法连接到我的项目,并且应用程序崩溃,并出现java.lang.NoClassDefFoundError:android.support.v7.appcompat.R $layout.
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "ua.appp.appp"
minSdkVersion 14
targetSdkVersion 21
versionCode 15
versionName "2.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.apis:google-api-services-calendar:v3-rev119-1.19.1'
compile 'com.google.api-client:google-api-client:1.19.1'
compile 'com.google.api-client:google-api-client-android:1.19.1'
compile 'com.google.api-client:google-api-client-gson:1.19.1'
compile 'com.github.navasmdc:MaterialDesign:1.+@aar'
compile 'com.afollestad:material-dialogs:0.6.5.2'
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0@aar'
compile 'com.nhaarman.listviewanimations:lib-core-slh:3.1.0@aar'
}
PS:一个有趣的事实:当我将所有这些库添加到测试项目中时,代码可以编译并且可以正常工作而不会出错.
解决方法:
当您添加multidex:true时,请不要忘记在项目中创建一个从MultiDexApplication扩展而来的Application类,否则会发生很多不好的事情
public class YourApplication extends MultiDexApplication {
..........
}
并且也不要忘记这一点(版本可能会随着时间的推移而变化,如果您阅读此书,请确保使用最新版本)
dependencies {
'com.android.support:multidex:1.0.1'
}
标签:android,android-gradle,build-gradle,google-api,google-calendar-api 来源: https://codeday.me/bug/20191013/1905117.html