Class not found exception when using Multidex

我的未来我决定 提交于 2019-12-08 13:26:52

问题


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:


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);
    }
}


来源:https://stackoverflow.com/questions/53579870/class-not-found-exception-when-using-multidex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!