【问题标题】:Cannot Resolve import android.support.multidex.MultiDex after change to newest Multidex更改为最新的 Multidex 后无法解决导入 android.support.multidex.MultiDex
【发布时间】:2015-12-15 10:05:48
【问题描述】:

我想在我的应用程序中使用 multidex,起初我使用了 depedencies: 'com.google.android:multidex:0.1',但是编译后出现这个错误:

错误:任务 ':packageAllDebugClassesForMultiDex' 执行失败。

java.util.zip.ZipException:重复条目:android/support/multidex/BuildConfig.class

然后我将'com.google.android:multidex:0.1' 更改为'com.android.support:multidex:1.0.1',但之后应用程序类中的import android.support.multidex.MultiDex; 无法解决,有人可以帮忙吗?

【问题讨论】:

    标签: android android-multidex


    【解决方案1】:

    将此添加到您的 build.gradile 中

     android {
        compileSdkVersion 21
        buildToolsVersion "21.1.0"
    
    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...
    
        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
    }
    
    dependencies {
    compile 'com.android.support:multidex:1.0.0'
    }
    

    将此添加到您的清单中

       <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.example.android.multidex.myapplication">
           <application
               ...
               android:name="android.support.multidex.MultiDexApplication">
               ...
           </application>
        </manifest>
    

    【讨论】:

    • 我已经把所有的代码都放在了前面,但是在我的应用程序类中 import android.support.multidex.MultiDex;无法解决。
    • 我的 AndroidManifest.xml 中仍然出现 unresolved 错误。
    • 按照上述步骤,在扩展应用程序的类中添加以下内容 protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
    【解决方案2】:

    你需要改变

    import android.support.multidex.MultiDexApplication;

    import androidx.multidex.MultiDexApplication;

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    【解决方案3】:

    在你的应用程序 gradle 中添加以下依赖项

     implementation 'androidx.multidex:multidex:2.0.1'
    

    【讨论】:

      猜你喜欢
      • 2011-01-08
      • 1970-01-01
      • 2021-11-20
      • 2022-11-23
      • 2013-08-08
      • 2013-03-11
      • 1970-01-01
      • 2019-04-01
      • 2015-11-17
      相关资源
      最近更新 更多