How to change Android App Name and ID of an existing application?

后端 未结 11 1571
刺人心
刺人心 2020-12-29 23:01

I have two Android projects in Eclipse. I copied the one project from the other, then changed the app name (in strings.xml) and the project name

相关标签:
11条回答
  • 2020-12-29 23:31

    Actually you need to change the name in several places:

    First, as you said, the name of the string, which is the visible name of the application.

    Second, go to activity->src and right click on the package (com.example.whatever) and do refactor->rename;

    Then go to the manifest.xml: and change the field in:

    <manifest package="com.example.whatever" >
    

    If you are using native code, JNI, you will also have to change the names of the c++ functions, which is a pain in the ass:

    Java_com_example_whatever_activity_function()
    
    0 讨论(0)
  • 2020-12-29 23:31

    I found that my rename wasn't working because I also needed to change the package name in google-services.json

    0 讨论(0)
  • 2020-12-29 23:42

    The most simple way I have found to accomplish this task is to utilize Product Flavor in .gradle

    productFlavors {
        MainApp {
            applicationId = "com.company.app"
        }
        NewAppFlavor {
            applicationId = "com.company.newapp"
        }
    }
    
    buildTypes {
        debug {
            buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" +  getDateAsMillis() + "L)"
            applicationIdSuffix ".debug"
        }
    }
    

    You then specify package name in AndroidManifest.xml as

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.company"
       android:versionCode="1"
       android:versionName="0.1.1" >
    

    Upon release configuration, Android Studio (1.5.1 as of this writing) will ask which flavor to build.

    Debug configuration is a little less intuitive, you must hover the cursor over the bottom left corner of the screen, select "Build Variants" and select which flavor your debug configuration will deploy when you press the play button.

    0 讨论(0)
  • 2020-12-29 23:44

    Select Android on the top left of the Project window. So, right click over your package name under Java folder and select "Refactor" -> Rename... Click in Rename Package Button. Type the name of the new package you want, mark all options then confirm.

    When it shows the results, click on "Do Refactor".

    0 讨论(0)
  • 2020-12-29 23:45

    My setup

    • Android Studio 3.5.3
    • Kotlin 1.3.x
    • macOS 10.14.6

    Solution to Renaming appid

    • In Project Explorer, find app/java/com.company.app.
    • Right-click > Refactor > Rename, then select Rename Package.
    • Look down in the Refactoring Preview and make sure all package references are selected.
    • Click Do Refactor.

    No need to hack around by hand.

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