Android Studio doesn't apply code changes - android

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.

Related

Locked with Android Studio

I am locked with Android Studio.
As I was developing my first android app, I sometime pushed the "Run 'app'" button to test and see how the app was working. With no problem up to this point, but then I tried to use Image Asset Studio to make my own icon. And now when I try to use the "Run 'app'" button to test, all I can see is the image below keeping coming back and the app is no longer started. I guess I did something wrong on the way; though I have no idea what. Can anyone think of what I should do to get back on my feet and have the app working again? I haven't changed any part of the code since it was last working.
And hereafter is a second screenshot showing an error:
Running the find command on the project directory, for the file ic_launcher.webp, I get this result.
I suppose some of the files shouldn't be there.
MyMac$ find AndroidStudioProjects/MyApp -name ic_launcher.webp
AndroidStudioProjects/MyApp/app/src/main/res/mipmap-mdpi/ic_launcher.webp
AndroidStudioProjects/MyApp/app/src/main/res/mipmap-hdpi/ic_launcher.webp
AndroidStudioProjects/MyApp/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
AndroidStudioProjects/MyApp/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
AndroidStudioProjects/MyApp/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
MyMac$
But for comparison if I run the same command on the directory for a project where this issue does not appear. I find even more of the ic_launcher.webp file, so I must be missing some detail.
MyMac$ find AndroidStudioProjects/MyOtherApp -name ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/build/intermediates/packaged_res/debug/mipmap-xxxhdpi-v4/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/build/intermediates/packaged_res/debug/mipmap-hdpi-v4/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/build/intermediates/packaged_res/debug/mipmap-xhdpi-v4/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/build/intermediates/packaged_res/debug/mipmap-mdpi-v4/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/build/intermediates/packaged_res/debug/mipmap-xxhdpi-v4/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/src/main/res/mipmap-mdpi/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/src/main/res/mipmap-hdpi/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
AndroidStudioProjects/MyOtherApp/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
MyMac$

How to Completely Remove an Android Layout from Android Studio

I'm building an app in Android Studio and I accidentally created a base LoginActivity template but then deleted it because I wanted to make my own. Now, when I try creating another activity with the same name, it tells me "Layout name must be unique."
I could just name it something else but:
I don't want to
There would still be some sort of duplicate files in my system doing nothing
My goal is to just remove all mentions of activity_login, ultimately so I can make a new activity with the same name, but I can't figure out how.
Go to res->layout->activity_login.xml and delete it from android studio
Or open project in file explorer, then Go to app/src/main/res/layout/activity_login.xml and delete it
If it didn't solve it, Invalidate Caches and restart Android Studio.
That's happens sometimes.
just go to : File->Manage IDE Settings -> Restore Default Settings.
This will solve it for sure :)
I had the same problem. Empty res/layout/activity_xxxxx.xml and invalidate cache didn't work, until I found there's xxxxx.java existing in app\src\main\java\com\example\xxxxx. After deleting the .java file as well, I found that I'm able to create the Activity file with the same name.

How to restore a deleted RunConfiguration in Android Studio?

I was trying to deal with a testing-related problem and I followed this advice:
https://stackoverflow.com/a/32267762/2576903
Now whenever I try to run my tests, I get prompted to choose a device.
How do I restore that build configuration?
I tried git commit to see changed files, but it seems that it was somewhere outside of the project folder. I also tried invalidating android studio's caches but nothing seems to work.
I tried creating another test class automatically (by control + enter on the name of a regular POJO) but the configuration wasnt created.
Went to the folder of my current test class,
created a new class
inserted annotation #RunWith(MockitoJUnitTestRunner.class)
right clicked the newly created class' name -> Run
and it created the configuration.

Generate Annotation files Automatically in Eclipse

I am using Annotations and svn(Version control) in my application. I have created one package inside of my application and some Activities inside of it. Now the application is perfectly running. I just committed the files to svn and tried to checkout files from another one pc. Now my projects contain some errors. The errors happen whenever I use intent for calling new Activity that shows an error. The error says "Summary_ cannot be resolved to a type"(Here I mention summary is my Activity name).
And I just add a space in that java file and save the error is gone. But I can not ask other peoples to do this every time. Because this also happen whenever the eclipse is restarted or when I clean my project . Checkout from svn. Update svn.
I guess the annotation files are not generated. Please anyone help me to solve this issue.
Note : I just added a space(or whatever) in that java file and saved. the error is gone . I want to know why it is happening?

Renamed Activity and now it won't launch

I renamed an Activity using Eclipse's refactor menu.
I cleaned the project and recompiled.
When I go to launch the Activity, the lines execute with no error.
Intent launchScreen = new Intent(this, ActivityMyScreen.class);
startActivityForResult(launchScreen, REQUEST_MYSCREEN);
I set a breakpoint in the onCreate method of the Activity being launched and it is never reached.
The only information Eclipse gives to me is in the LogCat, where it says the following every time startActivityForResult is called...
Initializing inflate state...
Any ideas?
There's a reference to the old activity name somewhere in your project. Probably the project's manifest file, but it may be elsewhere.
The easiest way to check would be to use Eclipse's search functionality to search the whole project for references to the old activity name, and correct any that it finds.
In my experience Eclipse does not always detect when it needs to rebuild the project in this situation, so it's also a good idea to clean and start a fresh build.
I'm a newbie, but I found checking (choosing) the following options did it for me without a glitch.
Update similarly named variables and methods (Be aware that you need to also choose Find exact names within the configure menu/link)
Update full qualified names in non-Java text files
Eclipse shows a preview of changes in all non-Java (manifest, etc.) files before committing the change.

Categories

Resources