135

My keystore is corrupt, therefore the Android Market is requiring me to rename the app and resubmit it. However, whenever I go to edit the package names in Manifest and throughout the files, it gives me tons of errors.

What's the proper way to change the application name?

Majid
  • 13,853
  • 15
  • 77
  • 113
Allen Gingrich
  • 5,608
  • 10
  • 45
  • 57
  • 3
    thankfully they added a "magical, change package name button" since 2010 - see @Marc Bernstein's answer - http://stackoverflow.com/a/4025633/383414 – Richard Le Mesurier Feb 08 '13 at 07:46
  • thanks Richard Le ... – DoruChidean Sep 07 '15 at 08:02
  • 3
    Possible duplicate of [Android Studio Rename Package](http://stackoverflow.com/questions/16804093/android-studio-rename-package) – Bo Persson Mar 20 '17 at 20:35
  • hard to be a duplicate when this was asked 3 years prior... – Ryan Ternier Mar 21 '17 at 06:20
  • [change package name in android studio](https://androidride.com/how-to-change-rename-android-app-package-name-android-studio/) – Athira Reddy Jul 15 '19 at 11:29
  • Note that since a while it is the `applicationId` defined in your app's `build.gradle` determining the package name of the app (which distinguishes it on the store). So to change your app's package name (and make it a completely separate app) it is sufficient to change the `applicationId` and it is no more necessary to change the `android:package` attribute in the manifest or change the package name of the Java sources. See https://developer.android.com/studio/build/application-id.html for details. – user905686 Apr 04 '21 at 14:24

19 Answers19

302

There is a way to change the package name easily in Eclipse. Right click on your project, scroll down to Android Tools, and then click on Rename Application Package.

Marc Bernstein
  • 11,423
  • 5
  • 34
  • 32
  • 2
    Just tried Eldar's and it worked - but I'm sure this will work, too. – Allen Gingrich Oct 26 '10 at 16:35
  • 4
    This is correct answer, but current ADT is broken, and it BREAKS every reference to your R class. So you have to click on each individual file, do "ctrl-shift-o" (or cmd-shift-o on Mac), and select your new-package-named R (DO NOT select android.R! things will break horribly), then hit save. ... and repeat for EVERY individual file :( – Adam May 17 '13 at 11:18
  • @Adam just to make our life more easier, click the project and use ctrl+shift+o, it will update the imported reference in ALL class/file :D – Blaze Tama Feb 14 '14 at 04:27
  • this just saved my life since I lost my ridiculous storekey and had to republish my application. – Teoman shipahi Mar 19 '14 at 03:11
  • 3
    i found the file package names declared at the top of each file to not to match the new package, nor the folder they are in. you can right click that source folder that still has the old package name (at least mine always does), select 'refactor' then 'rename' and rename it to the new package. eclipse will then rename the folder and the package declarations of each file to the new package name, like it should have done in the first place. – Androidcoder Apr 20 '14 at 19:50
  • i should have read this answer first, would have same me some time. thanks. – steveh Jun 26 '14 at 23:27
  • Just tried it out. It worked like a charm with Eclipse 3.8.1 and Android SDK Version 20. So whatever may have been broken is fixed now. – Nantoka Sep 09 '14 at 10:06
  • You will still need to manually edit required package name in your XML files. i.e. manifest.xml – atulkhatri Feb 11 '15 at 14:35
101

If you're using Eclipse, you could try these instructions from Android's developer site. They're specifically for the GestureBuilder sample but should apply to any application as far as I can tell:

[H]ere's how you could do this in Eclipse:

  1. Right-click on the package name (src/com.android.gesture.builder).
  2. Select Refactor > Rename and change the name, for example to com.android.gestureNEW.builder.
  3. Open the manifest file. Inside the <manifest> tag, change the package name to com.android.gestureNEW.builder.
  4. Open each of the two Activity files and do Ctrl-Shift-O to add missing import packages, then save each file. Run the GestureBuilder application on the emulator.

Also, be sure you remembered to rename the package itself along with the references to it in the files. In Eclipse you can see the name of the package in the file explorer window/tree view on the left hand side. In my experience, Eclipse can sometimes be a little finnicky and unreliable with this (leaving behind stray references to the old package name, for example).

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
51

Here's how you could do this in Eclipse:

  1. Right-click on the package name (src/com.android.gesture.builder).
  2. Select Refactor > Rename and change the name, for example to com.android.gestureNEW.builder.
  3. Open the manifest file. Inside the <manifest> tag, change the package name to com.android.gestureNEW.builder.
  4. Open each of the two Activity files and do Ctrl+Shift+O to add missing import packages, then save each file.
  5. Run the GestureBuilder application on the emulator.

Link to post

Update super easy way right click on your project... enter image description here

El Bert
  • 2,958
  • 1
  • 28
  • 36
AZ_
  • 21,688
  • 25
  • 143
  • 191
12

In Android Studio, which, quite honestly, you should be using, change the package name by right-clicking on the package name in the project structure -> Refactor -> Rename...

It then gives the option of renaming the directory or the package. Select the package. The directory should follow suit. Type in your new package name, and click Refactor. It will change all the imports and remove redundant imports for you. You can even have it fix it for you in comments and strings, etc.

Lastly, change the package name accordingly in your AndroidManifest.xml towards the top. Otherwise you will get errors everywhere complaining about R.whatever.

Another very useful solution

First create a new package with the desired nameby right clicking on thejava folder -> new -> package.`

Then, select and drag all your classes to the new package. AndroidStudio will re-factor the package name everywhere.

After that: in your app's build.gradle add/edit applicationId with the new one. i.e. (com.a.bc in my case):

defaultConfig {
    applicationId "com.a.bc"
    minSdkVersion 13
    targetSdkVersion 19
}

Original post and more comments here

General Grievance
  • 4,555
  • 31
  • 31
  • 45
craned
  • 2,991
  • 2
  • 34
  • 38
  • Weirdly, when I do that, it does not give the choice directory/package ... only the "module name" ... – Fattie May 21 '14 at 13:56
  • 1
    It does the same to me right now if I right-click on the root directory. At least for me, that's not my actual package name. If your package name is com.a.bc, there should be a directory below the root directory called bc. That's where you'll get the different options. Right now, I'm getting directory or module. Try module. You can always undo it (Ctrl+z should do it) if it breaks anything. – craned May 21 '14 at 14:31
  • Thanks .. shit, you mean the ".idea" directory or the "app" directory? I've just posted an explanatory Q .. http://stackoverflow.com/questions/23786361/android-studio-mac-fully-change-project-name Ahh .. I now see "Select refactoring directory/module" when I click on my "app" folder.... hoy caramba! – Fattie May 21 '14 at 14:38
  • @JoeBlow right click on `package` under the folder `java` – Abu Shumon Oct 30 '14 at 14:42
  • "Android Studio, which, quite honestly, you should be using" Keeping in mind that the question was asked in 2010, while AS wasn't even announced until 2013, let alone released as a stable build (2014). Granted, users *nowadays* should be using AS. :-) – LarsH Jan 04 '19 at 16:00
8

Without Eclipse:

  1. Change package name and Activity names in AndroidManifext.xml and anywhere else it shows up in .xml files (custom view names, etc)

  2. Update package import statement across all source files

  3. Rename all folders to match the package name. Folder locations:
    a. bin/classes
    b. gen
    c. src

  4. Update the project name in build.xml (or your apk's name won't change)

  5. Delete all the .class files in bin/classes/com/example/myapp/ (if you skip this step the files don't get rewritten during build and dex give a bunch of trouble processing "class name does not match path" errors

  6. Delete gen/com/example/myapp/BuildConfig.java (I don't know why deleting BuildConfig.class in step 3a didn't cause dex to update it's path to this, but until I deleted BuildConfig.java it kept recreating gen/com/oldapp_example/oldapp and putting BuildConfig.class in there. I don't know why R.java from the same location doesn't have this problem. I suspect BuildConfig.java is auto-generated in pre-compile but R.java is not)

The above 6 steps are what I did to get my package name changed and get a successful* build. There may be a better way to handle steps 5 and 6 via dex commands to update paths, or perhaps by editing classes.dex.d in the root directory of the project. I'm not familiar with dex or if it's ok to delete/edit classes.dex.d so I went with the method of deleting .class files that I know will be regenerated in the build. I then checked classes.dex.d to see what still needed to be updated.

*No errors or warnings left in my build EXCEPT dex and apkbuilder both state "Found Deleted Target File" with no specifics about what that file is. Not sure if this shows up in every build, if it was there before I messed with my package name, or if it's a result of my deletions and I'm missing a step.

clusterflux
  • 201
  • 2
  • 7
  • I solved the rename as you did, but with a simplification: delete bin and gen folders. Also I couldn't import the renamed project in Eclipse until I modified the hidden file .project, it had the old project name under – Jose_GD Nov 20 '13 at 22:39
6

Follow these steps:-

  • Right click on the project.
  • Go to Android tools.
  • Click on Rename Application Package.
  • Change the application package name.

DONE

Deepak Sharma
  • 4,999
  • 5
  • 51
  • 61
6

The fastest way to do that in Android Studio 1.3:

  1. Change the package name in the manifest
  2. Go to Module Settings[F4]-> Flavors, into Application Id write the same name.
  3. Create new package with that name: [right-click-> new-> package]
  4. Select all java files of your project and then proceed [Right-click-> Refactor-> Move-> {Select package}-> Refactor]

P.S. If you will not follow this order you can end up changing all the java files one by one with new imports and a bunch of compile time errors, so the order is very important.

Movsar Bekaev
  • 888
  • 1
  • 12
  • 30
  • 1
    With this method, the R remains unchanged by the refactoring. so import com.app.myapp.R DOES NOT change to the new package name, and you have to take one by one... – OWADVL Oct 07 '15 at 10:12
  • @OWADVL, R changes automatically when you move files to the new package, Android Studio automativally performs rebuilding when you move .java files, I do this thing every day and as long as I keep this order, I never change anything in .java files manually – Movsar Bekaev Oct 08 '15 at 07:35
  • But in Eclipse, we could change the app package ID, without changing the package of all the code. The wizard would rename BuildConfig & R references for you. I'm puzzled that the same thing doesn't exist in AS. – Tom Feb 09 '16 at 03:47
5

Changing package name is a pain in the ass. It looks like different methods work for different people. My solution is quick and error free. Looks like no cleaning or resetting eclipse is needed.

  1. Right click on the package name then Refractor > Rename.
  2. Right click on the project name Android tools > Rename Application Package.
  3. Manually set the package names in the Manifest that have not been changed by the previous steps.
erdomester
  • 11,789
  • 32
  • 132
  • 234
3
  1. Fist change the package name in the manifest file
  2. Re-factor > Rename the name of the package in src folder and put a tick for rename subpackages
  3. That is all you are done.
Sathirar
  • 331
  • 4
  • 17
  • I tried using Marc Bernstein's Android Tools->Rename Application Package, but it gave me error. This was simpler, though I had to fix some things after the change – david-hoze Aug 22 '13 at 12:34
3

Bernstein has the method, use the Eclipse tool, "Rename Application Package", you may have to do some clean-up even after the fact. Also, Eclipse sometimes loses track of things when you make changes to a project. You may have to use the "Clean Project" tool (under the "Project" menu.) If that doesn't work, you may have to close and restart Eclipse. Voo-doo solutions, but Eclipse can be that way.

m0j0
  • 39
  • 3
3

I found the easiest solution was to use Regexxer to replace "com.package.name" with "com.newpackage.name", then rename the directories properly. Super easy, super fast.

robisaks
  • 193
  • 1
  • 9
2

There is also another solution for users without Eclipse, simply change the package attribute in <manifest> tag in AndroidManifest.xml, by replacing the the old package name used with a new one. Note: You have to adjust the all the related import statements and related folders manually in your project than, too.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="new.package.name"
    .....
</manifest>
LikeYou
  • 500
  • 1
  • 6
  • 20
2

In Android Studio 1.2.2 Say if you want to change com.example.myapp to org.mydomain.mynewapp You can follow the steps in each of the directories as displayed in the below screen shot. It will give you the preview option so that you can preview before making any changes.

Go to Refactor -> Rename and give your new name. You have to do it for each of the folders, say for com, example and myapp. It will automatically update the imports so that you don't have to worry about it. enter image description here

Also update the file build.gradle which is not updated automatically.

defaultConfig {
        applicationId "org.mydomain.mynewapp" //update the new package name here
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

After that it will ask for sync do it. Then everything will be fine. I'm able to upload my APK to google store after this. Make sure you have signed your app to upload it to the store.

Anup
  • 4,024
  • 1
  • 18
  • 27
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
1

Alternative:

  1. Open AndroidManifest.xml
  2. Change package="NEW NAME" within manifest tag.
MapleLover
  • 665
  • 5
  • 7
1
  1. Right Click on Project >Android Tools >Rename Application Package

  2. Go to src and right click on your main package >Refactor >Rename

  3. Go to manifest file and change your package name .

PassKit
  • 12,231
  • 5
  • 57
  • 75
ritesh4326
  • 687
  • 7
  • 9
1

I just lost few hours trying all solutions. I was sure, problem is in my code - apk starting but some errors when working with different classes and activities.

Only way working with my project:

  1. rename it - file/rename and check all checkboxes
  2. check for non renamed places, I had in one of layout old name still in tools:context="..
  3. create new workspace
  4. import project into new workspace

For me it works, only solution.

Dudeist
  • 363
  • 1
  • 4
  • 13
1

So, using IntelliJ with Android (Studio) plugin was: I went to AndroidManifest.xml on top and changed package name by right-clicking -> Refactor -> rename. Our then package name had four parts a.b.c.d, the new one only a.b.c. So I renamed the first three. Then I went to the directory of generated sources (app\build\generated\source\r\development\debug\a\b\c\d), right-clicked R class and Refactor->Move[d] it to one package higher. Same with BuildConfig in app\build\generated\source\buildConfig\development\debug\a\b\c\d.

By using Refactor->Move, IntelliJ updates all references to BuildConfig and R.

Finally I updated all applicationId[s] I found in gradle.build I found. I hit Clean Project, Make and Rebuild Project. Deleted the app from my phone and hit "Play". It all worked out so refactoring was easy and quite fast.

Raul Pinto
  • 1,095
  • 8
  • 15
1
  1. In your Android studio , at project panel , there is gear icon "Click on it".
  2. Uncheck the Compact Empty Middle Packages
  3. Now the package directory has been broken up i.e individual directories.
  4. Select the directory you want to rename.
  5. Right click on that particular directory.
  6. Select refactor and then rename option.
  7. The dialog box has been open up,rename it.
  8. After putting new name, click on Refactor.
  9. Then click on Do Refactor at bottom.
  10. Then android studio will update all changes.
  11. Now open build.gradle file and update the applicationId & sync it.
  12. Now go to manifest file and rename the package.
  13. Rebuild your Project.
  14. You are done :)
Hanisha
  • 849
  • 10
  • 8
0

If you are looking for a quick and safe solution to change the package name, then I suggest you use the plugin "Android Package Renamer", It is available on Android Studio Market.

What you need to do is

  • enter "Your package name you want to change"
  • Click OK.

You can see the detailed answer here

Phuc VR
  • 111
  • 1
  • 3