Android Multidex 支持库已禁用
Android Multidex support library is disabled
我的应用程序在支持 multidex 时遇到了一些问题,实际上应用程序安装正常,但在此过程中,一些活动崩溃了,应用程序重新启动了主 activity。在 logcat 我发现了这个 :
I/MultiDex: install
I/MultiDex: VM has multidex support, MultiDex support library is disabled.
但我遵循了启用 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'
...
应用程序 class 扩展了 Multidex :
public class MyApplication extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
我不知道我到底缺少什么来摆脱这件事
提前致谢。
I/MultiDex: install I/MultiDex: VM has multidex support, MultiDex
support library is disabled.
你应该设置
public class MyApplication extends Application {
清单
<application
android:name=".MyApplication"
....>
然后清理-重建-运行 .
还要补充到上面的答案^
在 Android 文档中它说,如果您的 minSdkVersion 为 21 或更高版本,则不需要 multidex 支持库。所以,我明白你为什么那样做 https://developer.android.com/studio/build/multidex.html#mdex-on-l
您有以下选项:
https://developer.android.com/studio/build/multidex.html#mdex-gradle
别忘了添加 build.gradle(app)
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
选项 1) 如果您不覆盖应用程序 class,请编辑您的清单文件以在标记中设置 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>
选项 2) 如果您覆盖应用程序 class,请将其更改为扩展 MultiDexApplication(如果可能),如下所示:
public class MyApplication extends MultiDexApplication { ... }
选项 3) 或者如果您确实覆盖了应用程序 class 但无法更改基础 class,那么您可以改为覆盖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);
}
}
警告:在 MultiDex.install() 完成之前,不要通过反射或 JNI 执行 MultiDex.install() 或任何其他代码。 Multidex 跟踪将不会跟踪这些调用,从而导致 ClassNotFoundException 或由于 DEX 文件之间的 class 分区错误而导致的验证错误。
我的应用程序在支持 multidex 时遇到了一些问题,实际上应用程序安装正常,但在此过程中,一些活动崩溃了,应用程序重新启动了主 activity。在 logcat 我发现了这个 :
I/MultiDex: install
I/MultiDex: VM has multidex support, MultiDex support library is disabled.
但我遵循了启用 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'
...
应用程序 class 扩展了 Multidex :
public class MyApplication extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
我不知道我到底缺少什么来摆脱这件事
提前致谢。
I/MultiDex: install I/MultiDex: VM has multidex support, MultiDex support library is disabled.
你应该设置
public class MyApplication extends Application {
清单
<application
android:name=".MyApplication"
....>
然后清理-重建-运行 .
还要补充到上面的答案^
在 Android 文档中它说,如果您的 minSdkVersion 为 21 或更高版本,则不需要 multidex 支持库。所以,我明白你为什么那样做 https://developer.android.com/studio/build/multidex.html#mdex-on-l
您有以下选项: https://developer.android.com/studio/build/multidex.html#mdex-gradle
别忘了添加 build.gradle(app)
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
选项 1) 如果您不覆盖应用程序 class,请编辑您的清单文件以在标记中设置 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>
选项 2) 如果您覆盖应用程序 class,请将其更改为扩展 MultiDexApplication(如果可能),如下所示:
public class MyApplication extends MultiDexApplication { ... }
选项 3) 或者如果您确实覆盖了应用程序 class 但无法更改基础 class,那么您可以改为覆盖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);
}
}
警告:在 MultiDex.install() 完成之前,不要通过反射或 JNI 执行 MultiDex.install() 或任何其他代码。 Multidex 跟踪将不会跟踪这些调用,从而导致 ClassNotFoundException 或由于 DEX 文件之间的 class 分区错误而导致的验证错误。