添加Firebase后获得Multidex错误本机Android



Logcat 输出:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define 
Lcom/google/firebase/iid/zzc;
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForStagingDebug'.
com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzc;

这是我的构建。格拉德尔文件:

apply plugin: 'com.android.application'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'io.fabric'
android {
}
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "app.test.test”
minSdkVersion 15
targetSdkVersion 23
versionCode 101
versionName “1.2.5”
multiDexEnabled true
resConfigs "en"
}
dataBinding {
enabled true
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
main.java.srcDirs += 'src/main/java/'
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
android {
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries true
maxProcessCount 8
}
aaptOptions {
cruncherEnabled false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.app_release
}
debug {
debuggable true
signingConfig signingConfigs.app_release
}
}
productFlavors {
production {
minSdkVersion 15
applicationId "app.test.test"
resValue "string", "app_name", "test"
resValue "string", "content_authority", "app.test.test.sync.StubContentProvider"
resValue "string", "account_type", "test.com"
dimension "mode"
}
configurations {
all*.exclude module: 'gson'
}
}
repositories {
def androidHome = System.getenv("ANDROID_HOME")
mavenCentral()
maven { url "$androidHome/extras/android/m2repository/" }
maven { url "https://repo.commonsware.com.s3.amazonaws.com" }
maven { url "https://raw.githubusercontent.com/layerhq/releases-android/master/releases/" }
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://s3-ap-southeast-1.amazonaws.com/jp-build-packages/ec-android-sdk' }
maven { url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/" }
maven { url "https://jitpack.io" }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven {
url 'https://maven.google.com'
}
}
dependencies {
provided fileTree(include: ['*.jar'], dir: 'libs')
annotationProcessor files('libs/butterknife-6.1.0.jar')
implementation files('libs/butterknife-6.1.0.jar')
implementation files('libs/retrofit-1.9.0.jar')
// segment - analyti
//crashlytics
implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true
}
implementation 'com.android.support:appcompat-v7:25.2.0'
implementation 'com.android.support:recyclerview-v7:25.2.0'
implementation 'com.android.support:cardview-v7:25.2.0'
implementation 'com.android.support:support-v4:25.2.0'
implementation 'com.android.support:design:25.2.0'
//multidex lib
implementation 'com.android.support:multidex:1.0.1'
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation 'com.felipecsl:gifimageview:1.1.0'
implementation 'com.squareup.okhttp:okhttp:2.3.0'
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
implementation 'net.the4thdimension:poly-picker:1.0.11'
implementation 'com.navercorp.pulltorefresh:library:3.2.3@aar'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.getbase:floatingactionbutton:1.10.0'
//play service
implementation ('com.google.firebase:firebase-core:10.2.4'){
exclude group: 'com.google.android.gms'
}
implementation ('com.google.firebase:firebase-messaging:10.2.4'){
exclude group: 'com.google.android.gms'
}
implementation ('com.google.firebase:firebase-appindexing:10.2.4'){
exclude group: 'com.google.android.gms'
}
implementation ('com.google.firebase:firebase-crash:10.2.4'){
exclude group: 'com.google.android.gms'
}
implementation 'com.google.android.gms:play-services-plus:10.2.4'
implementation 'com.google.android.gms:play-services-location:10.2.4'
implementation 'com.google.android.gms:play-services-gcm:10.2.4'
implementation 'com.google.android.gms:play-services-auth:10.2.4'
implementation 'com.google.android.gms:play-services-
analytics:10.2.4'
implementation project(':PlaceAutoComplete')
implementation files('libs/gson-2.8.0.jar')
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
}
apply plugin: "com.google.gms.google-services"

我知道有很多库,但它工作正常,突然它给我抛出了多个 dex 的错误。我已经更新了我的 Sdk 平台和 Sdk 工具,但仍然无法正常工作。

我知道有很多库,但它工作正常,突然它给我抛出了多个 dex 的错误。我已经更新了我的 Sdk 平台和 Sdk 工具,但仍然无法正常工作。

我知道有很多库,但它工作正常,突然它给我抛出了多个 dex 的错误。我已经更新了我的 Sdk 平台和 Sdk 工具,但仍然无法正常工作。

按如下方式配置 multidex:

android {    
defaultConfig {
// Enable multidex support for android versions grater than API 21
multiDexEnabled true
}  
}
dependencies {
// Enable multidex support for android versions lower than API 21
compile 'com.android.support:multidex:1.0.0'
}

像这样为低于 API 21 的 android 版本扩展应用程序类:

public class MultiDexApp extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

现在,在清单文件中添加应用程序类:

<application
android:name=".MultiDexApp" <!-- enable application class -->
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

注意:如果您的项目配置为使用 minSdkVersion 20 或更低版本的 multidex,并且您部署到运行 Android 4.4(API 级别 20(或更低版本的目标设备,则 Android Studio 会停用即时运行。

有关此链接的更多详细信息。

最新更新