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

4

11

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..

Nappie answered 12/11, 2014 at 13:59 Comment(1)
I have the same problem. Did you find a solution ?Africa
C
31

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.

Coper answered 19/12, 2017 at 19:15 Comment(3)
i tried everything except invalidate caches part. after doing that it fixed everythingReposition
Worked for me!!Unknown
Maybe add a 5th step, I did all this and there was one more thing wrong: When I renamed the package in my project, it somehow also edited my Run/Debug Configurations. Make sure Launch under the Launch Options section is not set to None. Usually, this should be Default Activity.Charentemaritime
L
3

It's best to rename packages so that you right click on package name - > refactor -> rename. So android studio automatically renames all that has to be renamed.

Lanky answered 12/11, 2014 at 14:2 Comment(2)
I did that but project did not renamed.. As you are saying.Nappie
Yes, If you have create project from android studio, your answer is 100% correct. But I am exported project from eclipse. So I am facing problem.Nappie
S
0

You need to clean the project after renaming the packages as for some reason it doesn't rebuild it after the rename. Choose Build -> Clean Project and then run it again - It should be fine

Secondbest answered 5/3, 2015 at 13:0 Comment(1)
I'm facing the same issue, unfortunately clean did not do the trickJonme
C
0

For anybody still having issues with the app installing, but not launching on devices or the emulator, even after invalidating caches and doing everything else:

When I renamed the package in my project, it somehow also edited my Run/Debug Configurations. Make sure Launch under the Launch Options section is not set to None. Usually, this should be Default Activity.

Charentemaritime answered 5/1, 2023 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.