java Android Studio E/dalvikvm:找不到类...从方法引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36816684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio E/dalvikvm: Could not find class... referenced from method
提问by Hyman Smith
I encountered a problem that seems to have something to do with the libraries in android studio.
I am having compiling errors like:
我遇到了一个问题,似乎与 android studio 中的库有关。
我有编译错误,如:
Could not find class 'android.os.PersistableBundle referenced from method com.example.Hyman.test1.MainActivity.access$super', Could not find class 'android.app.SharedElementCallback referenced from method com.example.Hyman.test1.MainActivity.access$super', Could not find class 'android.app.ActivityManager$TaskDescription.
找不到从方法 com.example.Hyman.test1.MainActivity.access$super 引用的类“android.os.PersistableBundle”,找不到从方法 com.example.Hyman.test1.MainActivity 引用的类“android.app.SharedElementCallback” .access$super',找不到类 'android.app.ActivityManager$TaskDescription。
The app still runs normally but when it comes to running a certain button event, it stops working. My friend has the same exact code as I do but in my case it doesn't work. I have tried upgrading to a latest API level and tried different gradle plugin version but the problem persisted. Thanks
该应用程序仍可正常运行,但在运行某个按钮事件时,它停止工作。我的朋友和我有完全相同的代码,但在我的情况下它不起作用。我尝试升级到最新的 API 级别并尝试不同的 gradle 插件版本,但问题仍然存在。谢谢
running android studio 2.0
gradle version 2.10
min sdk 4.0
运行 android studio 2.0
gradle 版本 2.10
min sdk 4.0
回答by MandisaW
I got this error in Android Studio v2.0 while building an empty child of AppCompatActivity from the (v7-appcompat) Support Library. Seems like the problem occurred when the Build Tools (Gradle v2.1.0, Android plugin v2.10) were upgraded afterthe corresponding support library upgrade (v23.3.0).
我在 Android Studio v2.0 中从 (v7-appcompat) 支持库构建 AppCompatActivity 的空子项时遇到此错误。似乎是在相应的支持库升级(v23.3.0)之后升级构建工具(Gradle v2.1.0,Android plugin v2.10)时出现的问题。
My solution:
我的解决方案:
- Remove the support-library dependency reference from my module-level build.gradle file(s)
- Clean the Project
- Restart Android Studio (possibly optional)
- Add the support-library back via Project Structure > Dependencies
- 从我的模块级 build.gradle 文件中删除 support-library 依赖项引用
- 清理项目
- 重启 Android Studio(可能是可选的)
- 通过Project Structure > Dependencies添加支持库
Seems to be working so far, although in future it would be nice to be able to specify an upgrade-order, or set up some kind of happens-before hierarchy for libraries/settings that are dependent on Build Tools.
到目前为止似乎工作正常,尽管将来能够指定升级顺序或为依赖于构建工具的库/设置设置某种发生之前的层次结构会很好。
回答by P Kuijpers
回答by JC_
What I think solved the issues for me (after trying above suggestions) Shrink the codeand use progaurd rulesexplained officially here
我认为为我解决了问题(在尝试了上述建议之后) 收缩代码并使用此处正式解释的progaurd 规则
As I am novice to Android Studio, feltthat my project, though a very small app, might be inflated by multiple experimental library inclusions + so many comments(and inactive code inside) causing 64K?(nopeIguess),illegitimate references(possibly!); just a intuitive guess after reading answer by @PKuijpers(thanks!). And honestly I didn't wanted to include multiDex because after also reading official document, I was sure that my app is not PokemonGo or NFS or big enough to qualify for multidex.
由于我是 Android Studio 的新手,我觉得我的项目虽然是一个非常小的应用程序,但可能会因包含多个实验性库 + 如此多的评论(以及里面的非活动代码)而膨胀,导致 64K?(不,我猜),非法引用(可能!) ; 在阅读@PKuijpers 的回答后只是一个直观的猜测(谢谢!)。老实说,我不想包含 multiDex,因为在阅读了官方文档后,我确定我的应用程序不是 PokemonGo 或 NFS 或大到足以符合 multidex 的条件。
回答by Sam
I have faced same issue. The issue is because of difference between android build tools version and the android support library(appcompat) version.
我遇到了同样的问题。问题是由于 android 构建工具版本和 android 支持库(appcompat)版本之间的差异。
You can resolve this issue by, Either update your build tool version and support library version to latestor you should use a appcompat library that is lower than the build tools versionand change it in your gradle file.
您可以通过以下方式解决此问题:将您的构建工具版本和支持库版本更新为最新版本,或者您应该使用低于构建工具版本的 appcompat 库并在您的 gradle 文件中更改它。
You can get all the revisions of the support library from here
您可以从这里获取支持库的所有修订版
For getting and updating your build version and support library version please check build.gradle file inside your app module
要获取和更新您的构建版本和支持库版本,请检查您的应用模块中的 build.gradle 文件