在Android Studio中成功构建应用程序后如何解决此问题 [英] How to resolve this after successful build of app in android studio

查看:148
本文介绍了在Android Studio中成功构建应用程序后如何解决此问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败.

**Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException:无法合并dex **

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex**

推荐答案

步骤1:修改模块级别的build.gradle文件以启用multidex,并将multidex库添加为依赖项,如下所示:

Step1: Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

第2步:如果您确实覆盖了Application类,请如下进行更改以扩展MultiDexApplication(如果可能):

Step 2: If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication { ... }

或者,如果您确实重写了Application类,但是无法更改基类,则可以改写attachBaseContext()方法并调用MultiDex.install(this)以启用multidex:

Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

更多信息,请检查此链接

这篇关于在Android Studio中成功构建应用程序后如何解决此问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆