【问题标题】:getting Multidex error native android after adding firebase添加firebase后得到Multidex错误本机android
【发布时间】:2017-08-16 08:36:32
【问题描述】:

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;

这是我的 build.Gradle 文件:

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"

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

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

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

【问题讨论】:

标签: android firebase


【解决方案1】:

如下配置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 会禁用 Instant Run。

有关此link 的更多详细信息。

【讨论】:

  • 你在哪个安卓版本上运行这个应用
  • 同样的问题。原因:com.android.dex.DexException:多个dex文件定义Lcom/google/firebase/iid/zzc
  • minSdkVersion 15 targetSdkVersion 23
  • @user3606902 禁用即时运行。比跑
  • 用问题分享你的 gradle 应用文件
猜你喜欢
  • 2019-01-05
  • 2018-10-26
  • 2015-03-07
  • 2018-12-08
  • 2020-01-31
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多