在我的构建中添加编译“com.google.firebase:firebase-firestore:11.4.2”后我遇到了问题。
一旦我添加它,它还会将 com.google.common 等添加到我的 dex 文件中,这是大约 27k 的额外引用,从而突破了 64k 的 dex 限制。
有谁知道这是为什么还是我做错了什么?
最佳答案
尝试将这些行添加到您的 build.gradle
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
这将启用 multidex 模式,这将允许您超过 64k 限制。 (阅读更多 here )
API低于21
如果您使用的 API 级别低于 21,那么您还需要添加支持库
gradle.build:
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
android.manafest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
如果您使用自定义 Application
类,请尝试使用以下之一
方案一
简单地覆盖 MultiDexApplication 类
public class MyApplication extends MultiDexApplication { ... }
解决方案2
覆盖 attachBaseContext
并使用 install(Application)
函数安装 MultiDex
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
关于android - 添加 com.google.firebase :firebase-firestore:11. 4.2 后出现 DexOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46614405/