构建错误(将字节码转换为dex时出错)

时间:2018-03-23 21:36:10

标签: java android gradle

当我尝试构建android项目时,我得到了如下错误。

  

错误:将字节码转换为dex时出错:原因:   com.android.dex.DexException:多个dex文件定义   Landroid /拱/生命周期/ LiveData $ LifecycleBoundObserver;

我多次搜索stackoverflow来解决这个问题,但我仍然有这个错误。

我认为这是因为某些库版本冲突造成的。 但我没有发现问题所在。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "my.app.idhere"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 4
        versionName "1.0.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = ['appIdRedirectScheme': android.defaultConfig.applicationId]
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    /*  This for anyone following along with the repo. Since you will have a different
  *   root URL, this code loads up a value from your gradle.properties file.
  */
    buildTypes.each {
        it.buildConfigField 'String', 'GOOGLE_API_BASE_URL', GoogleApiBaseUrl
        it.buildConfigField 'String', 'IBM_API_BASE_URL', IBMApiBaseUrl
    }

    packagingOptions {

        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

//    dexOptions {
//        preDexLibraries = false
//    }

}

repositories {
    mavenCentral()
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:27.1.0'

    // compile group: 'com.cloudant', name: 'cloudant-sync-datastore-android', version:'1.1.5'

    // Google Play Services
    implementation 'com.google.android.gms:play-services-maps:12.0.0'
    implementation 'com.google.android.gms:play-services-location:12.0.0'
    implementation 'com.google.android.gms:play-services-places:12.0.0'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    implementation 'com.ibm.mobilefirstplatform.clientsdk.android:analytics:1.2.+'
    implementation 'com.ibm.mobilefirstplatform.clientsdk.android:push:3.7.0'
    implementation 'com.github.ibm-cloud-security:appid-clientsdk-android:3.+'


    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'com.google.firebase:firebase-messaging:12.0.0'

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

    implementation 'com.android.volley:volley:1.0.0'

    implementation 'com.android.support:cardview-v7:27.1.0'

    // compile 'commons-io:commons-io:2.4'

    // Mapbox

    implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.0@aar') {
        transitive = true
    }
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.11.1'
    implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.11.1') {
        transitive = true
    }

    implementation 'com.android.support:multidex:1.0.1'

}

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
  

注意:当我从gradle中删除mapbox时,错误消失了,但我需要使用mapbox。

1 个答案:

答案 0 :(得分:2)

最后,我通过添加这个gradle解决了这个问题。

  

实现“android.arch.lifecycle:extensions:1.1.1”

添加multidex并清理并重建项目后再次给我一个生命周期错误。

通过添加上面的gradle来修复该问题。