Execution failed for task ':app:transformClassesWithDexForDebug' while implementing Google sign in for Android

*爱你&永不变心* 提交于 2019-11-26 22:51:47
Alberto Crespo

Maybe this link helps you. link

That helped me:

android {
...
defaultConfig {
    ...
    multiDexEnabled true
    }
}

This problem occurs because of multiple inclusion of dependencies. You are including a dependency that is already specified in your build.gradle file. For example:

compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-identity:9.0.2'

the above specification of dependency will generate this problem, because play-services includes everything, including play-services-identity, & so, here the same dependency is included for multiple times.

The recommended option is to only include those dependencies that you actually need. If you need play services location & maps, only include these dependencies as:

compile 'com.google.android.gms:play-services-location:9.0.2'
compile 'com.google.android.gms:play-services-maps:9.0.2'

Without including everything with 'com.google.android.gms:play-services:9.0.2'.

In your specific case, I suspect the conflict is arising between google-services of the top level gradle file and play-services-identity & play-services-plus in the app level gradle file. Using only those services that you specifically need resolving multiple inclusion will resolve your issue.

In general, you should not use "multiDexEnabled true" if you don't have a strong & legitimate reason. Using it without knowing the actual problem means that you are bypassing a problem. You are allowing multiple overlapping dependencies yielding a potential source of api conflicts & bigger apk size.

Adding

 dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }

in with in android in build.gradle works for me.

Had the same problem.
Mine was fixed by setting the JAVA_HOME variable to java 8 jdk

export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"   
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!