【问题标题】:Error when Multidex Enabled启用 Multidex 时出错
【发布时间】:2018-07-11 09:39:50
【问题描述】:

我最近不得不在我的 android studio 项目中启用 multidex,这是用导入的模块构建的。它在主项目中表现良好,但在使用导入(来自主项目)模块构建的项目中显示多索引问题。我已经按照this 文档启用了multidex。由于application 标签没有被覆盖,所以我遵循了相关的方法。现在我收到此错误:

任务“:app:transformClassesWithMultidexlistForDebug”执行失败。 java.io.IOException: Can't write [E:\something\SalesDemo >Updated\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't >read [E:\something\SalesDemo >更新\app\build\intermediates\classes\debug(;;;;;;**.class)](看不懂[com]>(看不懂[smth](看不懂[infolinkplus])看不懂
[some.class](重复的 zip 条目
[com/abc/def/some.class]))))))

这是我的build.gradle

apply plugin: 'com.android.application'

//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion 25
  // buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "com.abc.def.somethingotherthing"
    multiDexEnabled true
    minSdkVersion 16
    //noinspection OldTargetApi
    targetSdkVersion 22
    versionCode 16
    versionName "0.0.16"
}

buildTypes {

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
//implementation 'com.android.support:multidex:1.0.3'
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.3'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'joda-time:joda-time:2.3'
compile 'com.google.android.gms:play-services-location:10.2.0'
compile project(':infolinkplus')
}

还有manifest 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.abc.def.somethingotherthing">

<application
    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning">
   ...
  //ACTIVITIES AND META-TAGS
  ...
    </application>


</manifest>

更改后,我运行干净的构建并重新构建,但没有结果。 我该如何克服这个问题?提前致谢。

【问题讨论】:

  • 您是否从MultiDexApplication 扩展了您的Application 类?
  • 添加你的android清单文件代码。
  • 没有。我没有,并试图避免它。 @安东
  • 如果您不想扩展 MultiDexApplication 并且您的项目中没有定义 Application 类,那么您可以使用 .
  • 我做到了。 @Vishalsharma

标签: java android android-multidex


【解决方案1】:

您必须更改您的Manifest 以提供MultiDex

<?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>

或者如果你有自定义的Application 类,你必须用MultiDexApplication 扩展它

public class MyApplication extends MultiDexApplication { ... }

【讨论】:

  • 已经做到了。添加了有问题的清单文件。请检查。
【解决方案2】:

重复的 zip 条目 [com/abc/def/some.class]

在您的项目中,您必须有一个名为 some.class 的类,将其重命名为其他名称

【讨论】:

    【解决方案3】:

    试试这个代码... 我希望你做这件事..

            multiDexEnabled true
        compile 'com.android.support:multidex:1.0.1'
    

    为应用程序级别创建类..

    public class MyApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }
    }
    
    
    
    
            android:name="MyApplication" > // here define that class name that extends by MultiDexApplication
    

    【讨论】:

    • ` // 在这里定义由 MultiDexApplication 扩展的类名 - 你是什么意思?
    • 如果您按照代码进入定义行,然后在应用程序标签中定义由 MultiDexApplication 扩展的包名和类名。
    • 我还是听不懂你在说什么。请解释编辑您的答案。请注意,我没有扩展 MultiDexApplication 的类。
    • 如果extends MultiDexApplication 中的MultiDexApplication 出现红色怎么办?
    • 我定义这个 MyApplication 扩展了 MultiDexApplication
    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多