我在将Google日历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
我尝试了很多选择,但是什么都没有起作用。当我将"multiDex true"
添加到defaultConfig
时,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'
}