运行 Android studio 3.0 Beta 5 中的应用程序时,我遇到了 Multidex 问题
I am facing Multidex issue while running the app in Android studio 3.0 Beta 5
我已经点击了此解决方案的各种链接,但没有任何效果。
以下是错误:
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我还启用了 multidex 并在 build.gradle 底部添加了 google 服务插件 file.Here 是 build.gradle 编译器依赖项:
compile fileTree(include: '*.jar', dir: 'libs')
compile files('libs/universal-image-loader-1.9.5.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:mediarouter-v7:26.0.1'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.daimajia.swipelayout:library:1.2.0@aar'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.+'
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile 'com.google.firebase:firebase-messaging:11.4.0'
compile 'junit:junit:4.12'
compile 'com.nineoldandroids:library:2.4.0'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'org.robolectric:shadows-multidex:3.1.2'
testCompile 'org.robolectric:shadows-httpclient:3.1.2'
testCompile 'org.robolectric:shadows-support-v4:3.1.2'
compile files('libs/beacon_sdk.jar')
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3') {
exclude module: "httpclient"
}
compile 'com.google.android.gms:play-services:11.4.0'
compile 'com.google.firebase:firebase-core:11.4.0'
compile 'org.apmem.tools:layouts:1.10@aar'
compile 'org.apache.commons:commons-lang3:3.5'
compile 'com.android.support:cardview-v7:26.0.1'
试试这个
split google play services 它会起作用
使用这个
compile 'com.google.android.gms:play-services-analytics:11.4.0'
compile 'com.google.android.gms:play-services-drive:11.4.0'
compile 'com.google.android.gms:play-services-location:11.4.0'
compile 'com.google.android.gms:play-services-places:11.4.0'
compile 'com.google.android.gms:play-services-gcm:11.4.0'
compile 'com.google.android.gms:play-services-plus:11.4.0'
代替这个
compile 'com.google.android.gms:play-services:11.4.0'
Android 5.0(API 级别 21)之前的平台版本使用 Dalvik 运行时来执行应用程序代码。默认情况下,Dalvik 将应用程序限制为每个 APK 一个 classes.dex 字节码文件。为了绕过这个限制,您可以将 multidex 支持库添加到您的项目中:
添加以下依赖项
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
如果您确实覆盖了应用程序 class 但无法更改基础 class,那么您可以改为覆盖 attachBaseContext() 方法并调用 MultiDex.install(this)启用 multidex:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
我已经点击了此解决方案的各种链接,但没有任何效果。 以下是错误:
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我还启用了 multidex 并在 build.gradle 底部添加了 google 服务插件 file.Here 是 build.gradle 编译器依赖项:
compile fileTree(include: '*.jar', dir: 'libs')
compile files('libs/universal-image-loader-1.9.5.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:mediarouter-v7:26.0.1'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.daimajia.swipelayout:library:1.2.0@aar'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.+'
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile 'com.google.firebase:firebase-messaging:11.4.0'
compile 'junit:junit:4.12'
compile 'com.nineoldandroids:library:2.4.0'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'org.robolectric:shadows-multidex:3.1.2'
testCompile 'org.robolectric:shadows-httpclient:3.1.2'
testCompile 'org.robolectric:shadows-support-v4:3.1.2'
compile files('libs/beacon_sdk.jar')
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3') {
exclude module: "httpclient"
}
compile 'com.google.android.gms:play-services:11.4.0'
compile 'com.google.firebase:firebase-core:11.4.0'
compile 'org.apmem.tools:layouts:1.10@aar'
compile 'org.apache.commons:commons-lang3:3.5'
compile 'com.android.support:cardview-v7:26.0.1'
试试这个 split google play services 它会起作用
使用这个
compile 'com.google.android.gms:play-services-analytics:11.4.0'
compile 'com.google.android.gms:play-services-drive:11.4.0'
compile 'com.google.android.gms:play-services-location:11.4.0'
compile 'com.google.android.gms:play-services-places:11.4.0'
compile 'com.google.android.gms:play-services-gcm:11.4.0'
compile 'com.google.android.gms:play-services-plus:11.4.0'
代替这个
compile 'com.google.android.gms:play-services:11.4.0'
Android 5.0(API 级别 21)之前的平台版本使用 Dalvik 运行时来执行应用程序代码。默认情况下,Dalvik 将应用程序限制为每个 APK 一个 classes.dex 字节码文件。为了绕过这个限制,您可以将 multidex 支持库添加到您的项目中:
添加以下依赖项
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
如果您确实覆盖了应用程序 class 但无法更改基础 class,那么您可以改为覆盖 attachBaseContext() 方法并调用 MultiDex.install(this)启用 multidex:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}