MultiDex support in Android application error

最后都变了- 提交于 2019-12-05 02:05:15

Gradle plugin v0.14.0 for Android adds full multidex support.
Remove all the build.gradle changes you made (for multidex), and simply add the following:

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

Trying adding the following code to your build.gradle, worked for me.

android{

...
dexOptions {
        preDexLibraries = false
    }

afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
            }
        }
    }
...
}

instead of including the entire google library, use only the ones you require.

for ex. use:

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

instead of

compile 'com.google.android.gms:play-services:7.8.0'

Try to disabled "Instant run":

In android studio: Menu File -> Settings

In Build, Execution, Deployment -> Instant run

UNCHECK Enabled Instant Run to hot swap code/resource changes on deploy (default enabled)

None of the answers they gave you were exhaustive. The problem lies in the Multidex. You must add the library in the app gradle :

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

After, add in the defaultConfig of the app gradle :

multiDexEnabled true

Your Application must be of the Multidex type.. You must write it in the manifest :

android:name=".MyApplication"

MyApplication must be either the Multidex class, or it must extend it.

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