gpt4 book ai didi

android - 为什么添加 google firebase 会导致 Dex 错误?

转载 作者:行者123 更新时间:2023-11-29 16:45:37 24 4
gpt4 key购买 nike

添加

implementation 'com.google.firebase:firebase-core:11.8.0'

我的模块 gradle 文件给我错误提示我的项目中有超过 64K 的方法。

我的猜测是我以某种方式实现了整个 google play 服务,尽管添加了

implementation 'com.google.android.gms:play-services-maps:11.8.0'

implementation '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

最佳答案

对主题中所述问题的简单回答是,您添加的依赖项只是将方法总数推到了 64K 以上,如您在错误消息中所见。听起来你假设它不应该,但显然它是。请记住,firebase-core 还引入了 firebase-analyics 和其他一些库,因此当您添加它时,您实际上获得的不仅仅是 firebase-core。

无论如何,你应该enable multidex在您的构建中防止在添加更多库时出现此错误。

关于android - 为什么添加 google firebase 会导致 Dex 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48566721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com