简体   繁体   中英

Android Studio E/dalvikvm: Could not find class… referenced from method

I encountered a problem that seems to have something to do with the libraries in android studio.
I am having compiling errors like:

Could not find class 'android.os.PersistableBundle referenced from method com.example.jack.test1.MainActivity.access$super', Could not find class 'android.app.SharedElementCallback referenced from method com.example.jack.test1.MainActivity.access$super', Could not find class '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

running android studio 2.0
gradle version 2.10
min sdk 4.0

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 after the corresponding support library upgrade (v23.3.0).

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

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.

I have faced same issue. The issue is because of difference between android build tools version and the android support library(appcompat) version.

You can resolve this issue by, Either update your build tool version and support library version to latest or you should use a appcompat library that is lower than the build tools version and change it in your gradle file.

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

Enabling Multidex solved the problem for me. More detailed explanation can be found at my answer on a similar question over here .

What I think solved the issues for me (after trying above suggestions) Shrink the code and use progaurd rules explained officially here

As I am novice to Android Studio, felt that 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM