使用Multidex时找不到类异常 [英] Class not found exception when using Multidex

查看:165
本文介绍了使用Multidex时找不到类异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的问题是,在设备上运行应用程序时出现找不到类"错误.

在路径io.tutorial.app上找不到

 "io.tutorial.app.App"类 

实际上,该路径中存在App.java类,而我的类也在扩展 MultiDexApplication .

到目前为止,我发现在内置的apk中生成了两个dex文件,即classes.dex和classes2.dex.奇怪的是,两个dex文件中都存在"io.tutorial.app"包(我认为这是问题所在).在 classes2.dex 文件中的"io.tutorial.app"包中没有任何类,但我的所有类都在同一包中的 classes.dex 文件中.io.tutorial.app".请帮助我找到解决方案.

清单:

 <应用程序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"工具:ignore ="GoogleAppIndexingWarning"><活动android:theme ="@ style/AppTheme.NoActionBarFullScreen"android:name =.ui.activity.SplashActivity"android:screenOrientation ="portrait"><意图过滤器>< action android:name ="android.intent.action.MAIN"/>< category android:name ="android.intent.category.LAUNCHER"/></intent-filter></activity> 

Gradle:app

https://pastebin.com/JpkRZY1G

应用类别:

 公共类App扩展了MultiDexApplication {@注入缓存缓存;公共无效onCreate(){AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);super.onCreate();initRemoteConfig();Injector.getInstance().init(this);Injector.getInstance().appComponent().inject(this);initFabric();initRealm();initPicasso();initRemoteConfig();initAds();initOneSignal();} 

解决方案

在怀疑的情况下,我会使用 @Inject 注释-或使用 Injector .

尝试改用 MultiDex.install():

 公共类App扩展了Application {...@Override受保护的void attachBaseContext(Context context){super.attachBaseContext(context);MultiDex.install(this);}} 

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

解决方案

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

这篇关于使用Multidex时找不到类异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆