Class not found exception when using Multidex

2019-06-09 10:32发布

So my problem is I'm getting Class not found error while running the app on my device.

"io.tutorial.app.App" class not found at the path io.tutorial.app

Actually the class App.java is present at that path and also my class is extending MultiDexApplication .

What I found so far is two dex files have generated in the built apk namely classes.dex and classes2.dex. The weird thing is the package "io.tutorial.app" is present at both dex files (I think this is the issue). There's no classes present at the "io.tutorial.app" package in the classes2.dex file but all my classes are present in classes.dex file under the same package "io.tutorial.app". Please help me to find a solution to this.

Manifest:

<application
    android:theme="@style/AppTheme"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_app"
    android:name="io.tutorial.app.App"
    android:allowBackup="true"
    android:supportsRtl="true"
    tools:ignore="GoogleAppIndexingWarning">

    <activity
        android:theme="@style/AppTheme.NoActionBarFullScreen"
        android:name=".ui.activity.SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

Gradle:app

https://pastebin.com/JpkRZY1G

App Class:

public class App extends MultiDexApplication {
@Inject
Cache cache;

public void onCreate() {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    super.onCreate();
    initRemoteConfig();
    Injector.getInstance().init(this);
    Injector.getInstance().appComponent().inject(this);
    initFabric();
    initRealm();
    initPicasso();
    initRemoteConfig();
    initAds();
    initOneSignal();
}

1条回答
贪生不怕死
2楼-- · 2019-06-09 11:08

I'd have that @Inject annotation under suspicion - or the use of Injector.

try to use MultiDex.install() instead:

public class App extends Application {
    ...
    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        MultiDex.install(this);
    }
}
查看更多
登录 后发表回答