简体   繁体   中英

Android Studio doesn't apply code changes

I created a simple method in the MainActivity named test()`, and then later I removed it 'cause it was not needed anymore. But after running the application again, I get the following error

java.lang.NoSuchMethodError: No virtual method test()Landroidx/lifecycle/LiveData; in class Lcom/shaunyl/navigationtest/user/model/UserViewModel; or its super classes (declaration of 'com.shaunyl.navigationtest.user.model.UserViewModel' appears in /data/data/com.shaunyl.navigationtest/code_cache/.overlay/base.apk/classes4.dex)
at com.shaunyl.navigationtest.MainActivity.onCreate(MainActivity.kt:70)

at line 70 of the file MainActivity there's not such a method of course, because I just removed it. But android studio keeps marking it (like caching it somewhere in the code_cache folder and never taking track of it), preventing the application to start up.

I have tried to delete the.idea folder, invalidate caches and restart android studio, and even restart the emulator. Nothing worked. Only thing that works is to wipe out emulator's data and restart it again.

But this is not a practical solution. Every time I write and then delete a method, or write and then delete a class, this issue pulls up.

Is there any solution to this annoying problem? Thanks

Answer based on my original comment above:

As you can see in the error message, the dex file in question with the obsolete reference to the removed method is on the device, not on your build area.

Simply uninstalling and reinstalling the app on the device should help. Or you can use the 'Clear storage' button in the app info view on the device.

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