简体   繁体   English

Android Multidex支持库已禁用

[英]Android Multidex support library is disabled

I'm experiencing some problem with multidex support in my app, in fact the app install normally, but through the process, some activities crashed and the app, relaunches the main activity. 我在应用程序中遇到多点支持问题,实际上该应用程序安装正常,但是在此过程中,一些活动崩溃了,该应用程序重新启动了主要活动。 In logcat I found this : 在logcat中,我发现了这一点:

I/MultiDex: install
I/MultiDex: VM has multidex support, MultiDex support library is disabled.

But I followed recommendations to enable Multidex support : 但是我遵循建议启用Multidex支持:

Gradle : 摇篮

compileSdkVersion 25
buildToolsVersion '25.0.2'

defaultConfig {
    applicationId "com..company.package"
    minSdkVersion 15
    targetSdkVersion 25
    multiDexEnabled true
    versionCode 21
    versionName "2.1.3"

}

dexOptions {
    javaMaxHeapSize "4g"
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile project(':rangebar')
compile('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') { transitive = true }
compile('com.weiwangcn.betterspinner:library-material:1.1.0') {
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
compile files('libs/itextpdf-5.5.9.jar')
compile 'com.android.support:multidex:1.0.1'
...

Application class extends Multidex : 应用程序类扩展了Multidex:

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

I don't know what I am exactly missing to get rid of this matter 我不知道要摆脱这个问题到底缺少什么

Thanks in advance. 提前致谢。

I/MultiDex: install I/MultiDex: VM has multidex support, MultiDex support library is disabled. I / MultiDex:安装I / MultiDex:VM具有Multidex支持,MultiDex支持库已禁用。

You should set 你应该设置

public class MyApplication extends Application {

Manifest 表现

<application
    android:name=".MyApplication"
   ....>

Then Clean-Rebuild-Run . 然后执行Clean-Rebuild-Run

But also to add to the answer on top^ 而且还要加在最上面的答案^

In the Android Documentation it says, if you have minSdkVersion is 21 or higher, you do not need the multidex support library. 在Android文档中说,如果您的minSdkVersion为21或更高,则不需要multidex支持库。 So, I see why you did that there https://developer.android.com/studio/build/multidex.html#mdex-on-l 所以,我明白了您为什么要这么做https://developer.android.com/studio/build/multidex.html#mdex-on-l

The options you have are the below: https://developer.android.com/studio/build/multidex.html#mdex-gradle 您可以使用以下选项: https : //developer.android.com/studio/build/multidex.html#mdex-gradle

Don't forget to Add in your build.gradle(app) 不要忘记在build.gradle(app)中添加

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
   }
    ...
}

Option 1) If you do not override the Application class, edit your manifest file to set android:name in the tag as follows: This will be your entry: android.support.multidex.MultiDexApplication 选项1)如果不重写Application类,请编辑清单文件以在标记中设置android:name,如下所示: 这将是您的输入:android.support.multidex.MultiDexApplication

<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
            <activity
                    android:name=".MainActivity"
                    android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
    </application>
</manifest>

Option 2) If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows: 选项2)如果您确实覆盖Application类,请如下进行更改以扩展MultiDexApplication(如果可能):

public class MyApplication extends MultiDexApplication { ... }

Option 3) 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: You add the code below without extending MultiDexApplication 选项3)或者,如果您确实重写了Application类,但是无法更改基类,那么您可以改写attachBaseContext()方法并调用MultiDex.install(this)以启用multidex: 您可以在下面添加代码而无需扩展MultiDexApplication

public class MyApplication extends **SomeOtherApplication** {

  //You add the code below without extending **MultiDexApplication**
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

Caution: Do not execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. 警告:在完成MultiDex.install()之前,请勿通过反射或JNI执行MultiDex.install()或任何其他代码。 Multidex tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files. Multidex跟踪将不会遵循这些调用,从而导致ClassNotFoundException或由于DEX文件之间的类分区不正确而导致验证错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM