Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After Renaming Package Name in android studio Launching error, Runtime Error

I have one project in android studio,

I have first exported project from eclipse to android studio. After that I have changed its package name in AndroidMenifest.xml,

rename directories from Android Studio,

Changes Package name in all my class files,

also changed position of R.java file

And gen folder like old was com.oldpath.path1 to com.newpath.path2.

Also reflect same in R.java file and BuildConfig.java file.

Now getting Error as follow..

    Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.oldpath.path1/com.newpath.path2.main.SplashScreen }
Error type 3
Error: Activity class {com.oldpath.path1/com.newpath.path2.main.SplashScreen} does not exist.

Please help me I am stuck in my project..

like image 678
Dharmik Avatar asked Nov 12 '14 13:11

Dharmik


1 Answers

Using Android Studio 3.0.1, it is not enough to just refactor the name of your package using the Refactor -> Rename... tool. First, as noted, this misses several references throughout your project, including within your Manifest file(s). Second, this misses generated-files and Android Studio cache (leading to the error identified by the OP).

For anyone stumbling on this, if you have not already renamed your package then follow these steps to do so: Rename package in Android Studio

Otherwise, if you've already tried and failed then the following steps will rescue your project:

Solution in Android Studio

  1. Use Ctrl+Shift+F to find and replace any references to your old package name that were missed by the refactor tool.
  2. Fix any remaining errors in your code, then clean and rebuild your application using Build -> Clean Project. This will regenerate your R file, fixing the last related build error, but giving you the startup error noted by the OP. Unfortunately, if you still have build errors then you're not quite facing the same issue as the OP...
  3. Prepare to restart the IDE (save your work and close any emulators that are running).
  4. From Android Studio, select File -> Invalidate Caches / Restart...

That's it! Android Studio will synchronize your Gradle file upon restarting, and from now on it will reference your new package name when starting your app.

like image 50
Design.Garden Avatar answered Oct 04 '22 17:10

Design.Garden