问题
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 :
I/MultiDex: install
I/MultiDex: VM has multidex support, MultiDex support library is disabled.
But I followed recommendations to enable Multidex support :
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 :
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.
回答1:
I/MultiDex: install I/MultiDex: VM has multidex support, MultiDex support library is disabled.
You should set
public class MyApplication extends Application {
Manifest
<application
android:name=".MyApplication"
....>
Then Clean-Rebuild-Run .
回答2:
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. So, I see why you did that there 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
Don't forget to Add in your 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
<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:
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
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 tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files.
来源:https://stackoverflow.com/questions/43228160/android-multidex-support-library-is-disabled