How to change package name of an Android Application

后端 未结 18 1153
攒了一身酷
攒了一身酷 2020-11-28 02:07

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 thro

相关标签:
18条回答
  • 2020-11-28 02:27

    Follow these steps:-

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

    DONE

    0 讨论(0)
  • 2020-11-28 02:29

    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.

    0 讨论(0)
  • 2020-11-28 02:30

    Alternative:

    1. Open AndroidManifest.xml
    2. Change package="NEW NAME" within manifest tag.
    0 讨论(0)
  • 2020-11-28 02:33

    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

    0 讨论(0)
  • 2020-11-28 02:33

    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.
    0 讨论(0)
  • 2020-11-28 02:33

    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.

    0 讨论(0)
提交回复
热议问题