androidandroid-studiogradle

Why does Android Studio build fail after main class rename?


I renamed the base class of my app before uploading to the Play Store and successfully completed a build and uploaded to the Play store.

com.app.bgd2.Bgd2Activity became com.app.bgd.Bgd2Activity

Now the second time I try to build, even after doing build clean from the android studio menus, and gradle clean on the command line I see this error:

Activity class {com.app.bgd2/com.app.bgd.Bgd2Activity} does not exist

So doing a grep for any file with the old string com.app.bg2 fails to find any appearance of the old string.

find . -type f  -exec grep bgd2 {} \;

What would cause this error? Is there another cache or other file to check that is outside the project folder/files?


What it looks like in the actual project:

--- a/android/app/src/main/java/com/scripturial/bgd2/Bgd2Activity.java
+++ b/android/app/src/main/java/com/scripturial/bgd/Bgd2Activity.java
@@ -1,8 +1,8 @@

-package com.scripturial.bgd2;
+package com.scripturial.bgd;

--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -5,13 +5,13 @@ plugins {
def buildWithCMake = project.hasProperty('BUILD_WITH_CMAKE');

android {
-    namespace = "com.scripturial.bgd2"
+    namespace = "com.scripturial.bgd"

And an actual screenshot,

Screenshot inside android studio

I have discovered an older version of this same question, but the solutions proposed do not work with the latest version of Android Studio. Older version


Solution

  • After trying all of the solutions listed [here](Package rename and error "Activity class does not exist") none of them worked. I upgraded gradle from 8.7 to 8.10 using the plugin menu, and that made the problem go away.

    I am unsure of what the underlying cause of this error was, but at least it fixed the problem. So I am recording it here as the answer to this problem in case anyone else has this problem.