Reputation: 5657
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?
Upvotes: 135
Views: 190551
Reputation: 171
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
You can see the detailed answer here
Upvotes: 0
Reputation: 3051
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 name
by right clicking on the
java 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
Upvotes: 13
Reputation: 887
Upvotes: 1
Reputation: 908
The fastest way to do that in Android Studio 1.3:
manifest
Module Settings[F4]-> Flavors
, into Application Id
write the same name.[right-click-> new-> package]
[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.
Upvotes: 6
Reputation: 6519
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.
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.
Upvotes: 2
Reputation: 1105
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.
Upvotes: 1
Reputation: 21899
Here's how you could do this in Eclipse:
src/com.android.gesture.builder
).Refactor > Rename
and change the name, for example to
com.android.gestureNEW.builder
. <manifest>
tag, change the package name to com.android.gestureNEW.builder
. Activity
files and do Ctrl+Shift+O to add missing import packages, then save each file. GestureBuilder
application on the emulator.Update super easy way right click on your project...
Upvotes: 51
Reputation: 363
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:
For me it works, only solution.
Upvotes: 1
Reputation: 627
Right Click on Project >Android Tools >Rename Application Package
Go to src and right click on your main package >Refactor >Rename
Go to manifest file and change your package name .
Upvotes: 1
Reputation: 5063
Follow these steps:-
DONE
Upvotes: 6
Reputation: 36193
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:
- Right-click on the package name (
src/com.android.gesture.builder
).- Select Refactor > Rename and change the name, for example to
com.android.gestureNEW.builder
.- Open the manifest file. Inside the
<manifest>
tag, change the package name tocom.android.gestureNEW.builder
.- 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).
Upvotes: 101
Reputation: 665
Alternative:
Upvotes: 1
Reputation: 201
Without Eclipse:
Change package name and Activity names in AndroidManifext.xml and anywhere else it shows up in .xml files (custom view names, etc)
Update package import statement across all source files
Rename all folders to match the package name. Folder locations:
a. bin/classes
b. gen
c. src
Update the project name in build.xml (or your apk's name won't change)
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
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.
Upvotes: 8
Reputation: 331
src
folder and put a tick for rename subpackages
Upvotes: 3
Reputation: 500
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>
Upvotes: 2
Reputation: 11829
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.
Upvotes: 5
Reputation: 193
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.
Upvotes: 3
Reputation: 39
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.
Upvotes: 3
Reputation: 11511
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.
Upvotes: 302