4

So I have tried to add the multidexenabled to my build.gradle file, invalidate caches and restart, clean project and build project and deleting all gradle cache folders. Can anyone see anything wrong with my gradle file?

Here is my exact error:

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

App file

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'

Project file

// 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
}

I have looked at many other questions and answers on here but cannot seem to find a solution that will rectify the problem :(

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

Here are the full list of my gradle dependencies:

Gradle Dependencies - Pastebin

3 Answers3

1

Try to add: implementation 'com.android.support:multidex:1.0.2' in your app gradle. Let me know if this works for you.

Pankaj Mundra
  • 1,401
  • 9
  • 25
0

This probably related to protobuf plugin as the documentation of Migrate to Android Plugin for Gradle 3.0.0 says (at the end of the page):

To use Protobufs, you must upgrade the Protobuf plugin to version 0.8.2 or higher.

So, change the plugin in your project (root) build.gradle to include the protobuf-gradle-plugin:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
  }
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Hi thanks for your reply, I have added my gradle project file for you but I already had this inside the file :( –  Nov 29 '17 at 16:06
  • How about changing `protobuf 'com.google.protobuf:protobuf-java:3.4.0'` to `compile 'com.google.protobuf:protobuf-java:3.0.0'`. Or try to commenting the line. Probably the sample project will help you: https://github.com/google/protobuf-gradle-plugin/blob/master/testProjectAndroid/build.gradle – ישו אוהב אותך Nov 29 '17 at 16:17
  • Hmmmm tried adding compile and even commenting out the line still getting error. Will look through sample project now - thanks! –  Nov 29 '17 at 16:27
  • Sorry, it should be implementation. Probably you need to exclude the protobuf from `io.grpc:grpc-protobuf` – ישו אוהב אותך Nov 29 '17 at 16:29
  • I changed it to implementation and commented out the io.grpc:grpc-protobuf still same error :( - I looked through the sample project and did make some changed but still same :( I will update the app gradle file in my OP - Thanks! –  Nov 29 '17 at 16:40
  • I didn't mean to excluding the dependency but adding exclude in the dependency. Something like this: `implementation('io.grpc:grpc-protobuf-lite:$grpcVersion') { exclude module: "protobuf-lite" }` – ישו אוהב אותך Nov 29 '17 at 16:43
  • Oh sorry, yes I have done that now and reflected changes in my OP - still same error haha. i will also update OP with exact error –  Nov 29 '17 at 16:59
  • Okay, try to commenting the ` implementation 'com.google.protobuf:protobuf-java:3.4.0'`. If still error, you need to find the problem which is probably a conflicted dependencies. Try running `gradlew.bat app:dependencies` in your root project via terminal/command prompt to find the conflicted library. It will show you the dependencies tree. – ישו אוהב אותך Nov 29 '17 at 17:09
  • Ok tried that and still getting error haha - will try to do what you said now! :) Thanks! –  Nov 29 '17 at 17:21
  • Hi there I have no idea to look through it and see what needs to be done as this is all new to me but what I have seen are numerous entries for the same dependency. I have added my output from the terminal at the the end of the OP if you really wouldn't mind taking your time to just quickly skim read through the link and see if you can spot anything? - Thanks! :) –  Nov 29 '17 at 17:29
0

Dex Errors might be probably because obfuscation tool like Proguard nullifies class files essential for the clean compile. Please exclude GMS and Firebase from obfuscation. Might help:

-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
-keep class com.firebase.** { *; }

Also please open all your layout .XML files and check if AS can build design without errors.

CodeBulls Inc.
  • 462
  • 3
  • 11
  • Hi thanks for your reply! I have added this in my android studio and my OP, but still same error :( This is error is getting really frustrating now haha –  Nov 29 '17 at 17:42
  • Please open all your layout .XML files and check if AS can build design without errors. – CodeBulls Inc. Nov 29 '17 at 17:47
  • Local History in AS might help you show all recent files changed, if you use one. I strongly suspect either EditText or a ListView has some problem in either the layout or in the implementation. – CodeBulls Inc. Nov 29 '17 at 17:54
  • Thanks, I get design editor is unavailable until a successful build when I click on the design tab for all my layout files :( Edit: I cannot preview but my friend can with the same project files, and he can get a successful preview of the all layout files –  Nov 29 '17 at 17:55
  • Last try before I bail out, In Proguard: -dontwarn com.google.firebase.** – CodeBulls Inc. Nov 29 '17 at 17:58
  • 1
    Haha tried that and no avail :( Thanks for your help really appreciate it! I am looking through the implementation side of things now but cannot really find anything. Running through inspect code atm –  Nov 29 '17 at 18:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/160128/discussion-between-codebulls-inc-and-avi312singh). – CodeBulls Inc. Nov 29 '17 at 18:17