无法将android studio 3.0.1中的dex与最新的gradle合并

所以我尝试将multidexenabled添加到我的build.gradle文件,使缓存无效并重新启动,清理项目和构建项目以及删除所有gradle缓存文件夹.任何人都可以看到我的gradle文件有什么问题吗?

这是我的确切错误:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

应用文件

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

ext {
    supportLibraryVersion = '27.0.1'
    grpcVersion = '1.4.0'
}

repositories {
    maven { url "https://plugins.gradle.org/m2/" }
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "aviraj.firebaseapp"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

        dexOptions {

            jumboMode true
            javaMaxHeapSize "4g"

        }
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

    signingConfigs {
        release {
            storeFile file(project.properties.storeFile)
            storePassword project.properties.storePassword
            keyAlias project.properties.keyAlias
            keyPassword project.properties.keyPassword
        }
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
    }


}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support:mediarouter-v7:27.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    implementation 'com.google.cloud:google-cloud-speech:0.30.0-alpha'
    implementation 'com.google.apis:google-api-services-speech:v1-rev21-1.23.0'


    implementation 'com.google.firebase:firebase-core:11.4.2'
    implementation 'com.google.firebase:firebase-auth:11.4.2'
    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.0.1'
    implementation 'com.google.android.gms:play-services-auth:11.4.2'
    implementation fileTree(dir: 'libs', include: ['*.jar'])


    //noinspection GradleCompatible
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"

    // gRPC
    implementation "io.grpc:grpc-okhttp:$grpcVersion"
    implementation('io.grpc:grpc-protobuf-lite:$grpcVersion') { exclude module: "protobuf-lite" }
    implementation "io.grpc:grpc-stub:$grpcVersion"
    implementation 'javax.annotation:javax.annotation-api:1.3.1'
    implementation 'com.google.protobuf:protobuf-java:3.4.0'

    implementation 'com.android.support:multidex:1.0.2'
    implementation 'com.android.support:multidex-instrumentation:1.0.2'

    // OAuth2 for Google API
    implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }

}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

task copySecretKey(type: Copy) {
    def File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
    from secretKey.getParent()
    include secretKey.getName()
    into 'src/main/res/raw'
    rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)


apply plugin: 'com.google.gms.google-services'

项目文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
        classpath 'com.google.gms:google-services:3.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我在这里看了很多其他的问题和答案,但似乎无法找到解决问题的解决方案:(

Logcat.txt

    11-29 15:01:45.332 3192-3192/aviraj.firebaseapp E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system
11-29 15:01:45.332 3192-3192/aviraj.firebaseapp W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
11-29 15:01:45.333 3192-3192/aviraj.firebaseapp I/art: Not late-enabling -Xcheck:jni (already on)
11-29 15:01:46.509 3192-3192/aviraj.firebaseapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-29 15:01:46.512 3192-3192/aviraj.firebaseapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-29 15:01:46.690 3192-3207/aviraj.firebaseapp W/art: Suspending all threads took: 18.126ms
11-29 15:01:46.695 3192-3192/aviraj.firebaseapp I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
11-29 15:01:46.699 3192-3207/aviraj.firebaseapp I/art: Background sticky concurrent mark sweep GC freed 2654(220KB) AllocSpace objects, 0(0B) LOS objects, 22% free, 870KB/1117KB, paused 20.288ms total 38.896ms
11-29 15:01:46.737 3192-3192/aviraj.firebaseapp D/FirebaseAuth: Notifying id token listeners about user ( dPtIj9CudnMzI3SRp9NVzA2609P2 ).
11-29 15:01:46.753 3192-3213/aviraj.firebaseapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-29 15:01:46.765 3192-3192/aviraj.firebaseapp D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
11-29 15:01:46.787 3192-3213/aviraj.firebaseapp I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
11-29 15:01:46.788 3192-3213/aviraj.firebaseapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
11-29 15:01:47.120 3192-3192/aviraj.firebaseapp I/FirebaseInitProvider: FirebaseApp initialization successful
11-29 15:01:47.121 3192-3192/aviraj.firebaseapp I/InstantRun: starting instant run server: is main process
11-29 15:01:47.137 3192-3216/aviraj.firebaseapp I/FA: App measurement is starting up, version: 11717
11-29 15:01:47.138 3192-3216/aviraj.firebaseapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
11-29 15:01:47.138 3192-3216/aviraj.firebaseapp I/FA: To enable faster debug mode event logging run:
                                                        adb shell setprop debug.firebase.analytics.app aviraj.firebaseapp
11-29 15:01:47.479 3192-3192/aviraj.firebaseapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-29 15:01:47.814 3192-3207/aviraj.firebaseapp I/art: Background sticky concurrent mark sweep GC freed 1024(125KB) AllocSpace objects, 0(0B) LOS objects, 8% free, 2MB/2MB, paused 6.067ms total 17.836ms
11-29 15:01:47.851 3192-3207/aviraj.firebaseapp W/art: Suspending all threads took: 5.990ms
11-29 15:01:47.856 3192-3207/aviraj.firebaseapp I/art: Background sticky concurrent mark sweep GC freed 2815(100KB) AllocSpace objects, 0(0B) LOS objects, 5% free, 2MB/2MB, paused 8.159ms total 18.179ms
11-29 15:01:47.895 3192-3192/aviraj.firebaseapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
11-29 15:01:47.901 3192-3192/aviraj.firebaseapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
11-29 15:01:47.941 3192-3216/aviraj.firebaseapp I/FA: Tag Manager is not found and thus will not be used
11-29 15:01:47.980 3192-3220/aviraj.firebaseapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-29 15:01:47.983 3192-3192/aviraj.firebaseapp D/gralloc_ranchu: Emulator without host-side GPU emulation detected. Loading gralloc.default.so from /vendor/lib/hw/gralloc.default.so...
11-29 15:01:47.983 3192-3192/aviraj.firebaseapp D/gralloc_ranchu: gralloc.default.so not found in /vendor. Trying /system/lib/hw/gralloc.default.so...
11-29 15:01:47.983 3192-3192/aviraj.firebaseapp D/Atlas: Validating map...
11-29 15:01:47.987 3192-3192/aviraj.firebaseapp D/FirebaseApp: Notifying auth state listeners.
11-29 15:01:47.988 3192-3192/aviraj.firebaseapp D/FirebaseApp: Notified 0 auth state listeners.
11-29 15:01:48.044 3192-3220/aviraj.firebaseapp I/OpenGLRenderer: Initialized EGL, version 1.4
11-29 15:01:48.047 3192-3220/aviraj.firebaseapp D/OpenGLRenderer: Enabling debug mode 0
11-29 15:01:48.134 3192-3192/aviraj.firebaseapp W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
11-29 15:01:49.236 3192-3192/aviraj.firebaseapp I/Choreographer: Skipped 64 frames!  The application may be doing too much work on its main thread.
11-29 15:06:48.122 3192-3213/aviraj.firebaseapp I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
11-29 15:06:48.122 3192-3213/aviraj.firebaseapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
11-29 15:23:26.747 3192-3192/aviraj.firebaseapp I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.

proguard-rules.pro

# Suppress warnings from gRPC dependencies
-dontwarn com.google.common.**
-dontwarn com.google.api.client.**
-dontwarn com.google.protobuf.**
-dontwarn io.grpc.**
-dontwarn okio.**
-dontwarn com.google.errorprone.annotations.**
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
-keep class com.google.firebase.**
-keep class io.grpc.internal.DnsNameResolveProvider
-keep class io.grpc.okhttp.OkHttpChannelProvider

以下是我的gradle依赖项的完整列表:

Gradle Dependencies – Pastebin

最佳答案 尝试添加:实现’com.android.support:multidex:1.0.2′

在你的应用程序gradle中.

如果这对您有用,请告诉我.

点赞