Fully change package name including company domain

后端 未结 16 2435
礼貌的吻别
礼貌的吻别 2020-12-13 01:11

Let\'s suppose this is the package name: package com.company.name. How do I change company?

P.S. I saw how to change name but

相关标签:
16条回答
  • 2020-12-13 02:01

    To rename the package name in Android studio, Click on the setting icon in the project section and untick the Compact empty Middle Packages, after that the package will split into multiple folder names, then right click on the folder you need to change the name, click on refactor-> Rename-> Type the name you want to change in -> Refactor -> Refactor Directory, then import R.java file in the whole project. Working for me.

    0 讨论(0)
  • 2020-12-13 02:06

    Hi I found the easiest way to do this.

    1. Create a new project with the desired package name
    2. copy all files from old project to new project (all file in old.bad.oldpackage=>new.fine.newpackage, res=>res)
    3. copy old build.graddle inside new build.graddle
    4. copy old Manifest inside new Manifest
    5. Backup or simply delete old project

    Done!

    0 讨论(0)
  • 2020-12-13 02:07

    I found another solution for renaming a package in the entire project:

    Open a file in the package. IntelliJ displays the breadcrumbs of the file, above the opened file. On the package you want renamed: Right click > Refactor > Rename. This renames the package/directory throughout the entire project.

    0 讨论(0)
  • 2020-12-13 02:09

    current package : com.company.name

    New package : com.mycomapny.name

    Steps: 1) Suppose you are at this screen which is shown below.

    2) Open project pane and click on settings icon.

    3) Deselect Compact Empty Middle Packages.

    4) Then your package is now broken into individual parts as shown below .

    5) right click on "company" select Refactor -> select rename ->rename directory.

    6) Now your "company" has been changed to new "mycomapny" and changes were reflected as shown in below figure.

    7) Now change the package name in AndroidManifest.xml file .

    8) Open app level build.gradle and change package name .

    9) you will get errors as Cannot resolve symbol "R" .

    10) Remove line which gives this error and studio will import new R file automatically.

    11) If you have multiple files then use find and replace option by pressing " Cntrl+Shift+R "

    Or " Select Edit->Find->Replace in path.."

    12) select Replace All.

    0 讨论(0)
  • 2020-12-13 02:11

    @Luch Filip's solution works well if you just want to rename the App package. In my case, I also want to rename the source package too, so as not to confuse things.

    Only 2 steps are needed:

    1. Click on your source folder e.g. com.company.example > Shift + F6 (Refactor->Rename...) > Rename Package > enter your desired name.

    2. Go to your AndroidManifest.xml, click on your package name > Shift + F6 (Refactor->Rename...) > enter same name as above.

    Step 1 will automatically rename your R.java folder, and you can build straight away.

    0 讨论(0)
  • 2020-12-13 02:13

    This might help you - 1) Open a file of your package. 2) Android Studio displays the breadcrumbs of the file, above the opened file. On the package you want renamed: Right click > Refactor > Rename.

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