23

I have an android phonegap project, and an ios phonegap project.

They were created using a given package name, but I now have to change this package name.

In Android, I think I have to change package name in manifest, plus rename/move the java file in the src folder, and change inside this java file to reflect the new package name. Then clean and build. Does this sound right?

I also noticed an option in Eclipse Android Tools >> Rename Application Package, where it asks for a package name. Would it make all necessary changes?

How would I change the bundle ID in the XCode project so the project builds ok? Just edit the Bundle identifier as explained in this ticket would do? Changing xcode package name without creating and importing to new project

Thanks for any help.

Community
  • 1
  • 1
Vero
  • 1,742
  • 3
  • 15
  • 29

5 Answers5

28

It would be better if instead of Renaming the .java file and the class name, you just make your changes in:

  • AndroidManifest.xml
  • config.xml

Then remove android support with cordova platform remove android
And then re-add the android support cordova platform add android

This will generate the .java file again with the correct name.

Ref: http://intown.biz/2014/03/07/renaming-a-cordova-application/

kumarharsh
  • 18,961
  • 8
  • 72
  • 100
  • 6
    Every changes in AndroidManifest.xml will be lost with **cordova platform remove android**, changes in config.xml are enough to see .java, packages and manifest recreated by **cordova platform add android** – phemt.latd Apr 13 '15 at 14:24
  • 1
    downvote because changes to AndroidManifest.xml are not necessary and the answer below with less upvotes provides a better answer. – andreimarinescu May 13 '16 at 11:10
  • 1
    This works. Now I can easily use test and prod versions next to each other without uninstalling the test version. I use a prefix for my package names `test` and `prod` – A.W. May 12 '21 at 14:14
23

As a command above, just 3 steps:

  • Remove platform cordova platform remove android

  • Edit config.xml (main folder) find & replace widget id

<widget id="com.foobar.mynewname" version="1.0.0" android-versionCode="1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  • Add platform again cordova platform add android
Guille Acosta
  • 2,051
  • 23
  • 35
9

Yes, basically just change the android:package attribute in your manifest, and then refactor your src/ folders to follow that same package name.

As an alternative you can use the rename option in Eclipse, but it will have to modify all of the R.class imports in any of your java files that use resources. This will look a little intimidating, but should work fine.

NPike
  • 13,136
  • 12
  • 63
  • 80
9

The files containing the project name are:

  • AndroidManifest.xml <-- package name
  • res/values/strings.xml <-- visible name in list
  • build.xml
  • config.xml

Go into src/your.project.name and open the .java file.

Under the license change the package name to the new package name to whatever you desire.

Use the same package name in AndroidManifest.xml "Package".

Attempt build and if that works then Modify the value in res/values/strings.xml.

Build again and go through each value until you are happy.

John McLear
  • 764
  • 1
  • 10
  • 20
2

in ios all you have to do is to change the config.xml attribute

<?xml version='1.0' encoding='utf-8'?>
<widget id="org.test.area" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>YourNewAppName</name>
    [...]

then as kumar suggested do a cordova platform remove ios then cordova platform add ios and cordova build ios then rebuild the project in xcode!

Bergrebell
  • 4,263
  • 4
  • 40
  • 53