添加
实施'com.google.firebase:firebase-core:11.8.0'
到我的模块gradle文件给出了错误,表明我的项目中有超过64K的方法。
我的猜测是我在某种程度上实现了整个Google Play服务,尽管添加了
实施'com.google.android.gms:play-services-maps:11.8.0'
或
实施'com.google.android.gms:play-services-location:11.8.0'
没有错误。
格拉德尔:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "se.workshop.collect"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation "com.android.support:recyclerview-v7:26.1.0" //Recycler View Support
implementation "com.android.support:cardview-v7:26.1.0" //Recycler View Support
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.0"
implementation 'com.karumi:dexter:4.2.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version:"$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
和错误:
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Error: at com.android.dx.merge.DexMerger$8.updateIndex(DexMerger.java:565)
Error: at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
Error: at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:574)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:166)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Information:BUILD FAILED in 13s
答案 0 :(得分:3)
主题中所述问题的简单答案是,您添加的依赖项只是将方法总数推到64K以上,如错误消息中所示。听起来你假设它不应该,但显然它是。请记住,firebase-core还引入了firebase-analysis和其他一些库,因此当你添加它时,你实际上不仅仅是firebase-core。
无论如何,您应该在构建中enable multidex以防止在添加更多库时出现此错误。