multiDexKeepFile ignored / not working

2019-08-08 19:19发布

My application is a custom class that extends MultiDexApplication.

public class CustomApp extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        //TODO
    }
}

In my AndroidManifest.xml :

<application
        android:name=".helper.CustomApp"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="${app_name}"
        android:largeHeap="true"
        android:screenOrientation="portrait"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:allowBackup, android:label">

When I try to run the apk on a samsung s6 (API 7.0), everything works fine. BUT, when I try to run it on a THOMSON (API 4.2.2), I get this error :

FATAL EXCEPTION: main
                                                            java.lang.RuntimeException: Unable to instantiate application me.blu.app.helper.CustomApp: java.lang.ClassNotFoundException: Didn't find class "me.blu.app.helper.CustomApp" on path: DexPathList[[zip file "/data/app/me.blu.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/me.blu.app-1, /vendor/lib, /system/lib]]
                                                                at android.app.LoadedApk.makeApplication(LoadedApk.java:504)

So this I did that - I created a multidex-config.txt and added this line :

me/blu/app/helper/CustomApp.class

This file is located right next to my build.gradle file as needed.

Then I added this multiDexKeepFile file('multidex-config.txt') in my two builTypes but ALSO below multiDexEnabled true.

It's still not working. I would higly appreciate some help ^^

Thanks.

1条回答
够拽才男人
2楼-- · 2019-08-08 19:45

I once facing with the same problems eventhough had adding the multidex. The problem arise whenever apk is running in Android 4.4 Xiaomi (If I remember it correctly). To solution is using MultiDex.install() in app like this:

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

Then adding the jumboMode true in module build.gradle:

android {
    ...
    dexOptions {
        jumboMode = true
    }

}
查看更多
登录 后发表回答