dex文件不包含MainActivity类 [英] dex file does not contain MainActivity class

查看:197
本文介绍了dex文件不包含MainActivity类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行我的应用程序时,出现以下错误:

When running my app I get the following error:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.name.app/com.name.app.MainActivity}: 
java.lang.ClassNotFoundException: Didn't find class "com.name.app.MainActivity" on path: 
    DexPathList[[zip file "/data/app/com.name.app-2/base.apk"],
        nativeLibraryDirectories=[/vendor/lib, /system/lib]]

我已经使用Android Studio apk分析器(构建">分析APK")分析了我的apk(app/build/outputs/apk/debug/app-debug.apk),classes.dex的结构为

I have used the Android Studio apk analyzer (Build > Analyze APK) to analyse my apk (app/build/outputs/apk/debug/app-debug.apk) and the structure of the classes.dex is

java/
    lang/*
    util/*
    io/*
com/google/devtools/build/...

我注意到我自己的类以及MainActivity都丢失了. 就我所了解的dex文件(来自这个 SO问题)我自己课程也应该在那里. 因为他们不在,所以我明白了为什么我得到找不到我的班级的错误.

I noticed that my own classes, and thus the MainActivity, are missing. For as far as I understand dex files (from this SO question) my own classes should be there, too. As they are not there, I see why I get the error that my class is not found.

我在自己的设备:Samsung,Lollipop 5.0.2,API 21和虚拟设备:Google Pixel,Oreo 8.0.0,API 26上收到此错误.

I get this error on my own device: Samsung, Lollipop 5.0.2, API 21, and on a virtual device: Google Pixel, Oreo 8.0.0, API 26.

我尝试过的事情

我在Google上搜索并找到了多个建议,但没有一个对我有用. 这些建议是:

I have googled and found multiple suggestions, but none of them worked for me. These suggestions were:

  • 禁用即时运行. 文件">设置">构建,执行,部署">即时运行">取消选中即时运行.

  • Disable instant run. File > Settings > Build, Execution, Deployment > Instant Run > uncheck instant run.

清理项目.生成>清理.然后重新构建项目,依次选择构建">重新构建".

Clean the project. Build > Clean. Then rebuild the project, Build > Rebuild.

使缓存无效/重启.

从设备上卸载应用程序,然后重试.

Uninstall the application from the device and try again.

Manifest中使用不同的路径命名.在activity标签中将android:name=".MainActivity"更改为android:name="com.name.app.MainActivity".

Use different path naming in the Manifest. Change android:name=".MainActivity" into android:name="com.name.app.MainActivity" in the activity tag.

禁用预删除功能,例如答案.

Disable pre-dexing, as in this answer.

build.gradle

dexOptions {
    preDexLibraries false
}

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