简体   繁体   中英

How to change the package name of my app in Android Studio?

I created a project in Android Studio. Android Studio generated a package name according to my app name. But I don't want that name ( com.randompasswordgenerator ). So I found all the occurences of the package name and changed it to com.passwordgen . However, when I run the app, in the Run console, it still uses the old name:

Installing com.randompasswordgenerator
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.randompasswordgenerator"
pkg: /data/local/tmp/com.randompasswordgenerator
Success
...

I tried to change the package name in the manifest but it is already automatically changed to the new name. I guess there is another place that I need to change the name, but where?

I know this has been asked a lot of times. But the posts I found uses Eclipse instead of Android Studio.

EDIT:

Here is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.passwordgen" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MyTheme" >
        <activity
            android:name=".MainMenuActivity"
            android:label="@string/app_name"
            android:theme="@style/MyTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".GenerateActivity"
            android:label="@string/title_activity_generate"
            android:theme="@style/MyTheme" >
        </activity>
        <activity
            android:name=".OptionsActivity"
            android:label="@string/title_activity_options"
            android:theme="@style/MyTheme" >
        </activity>
        <activity
            android:name=".PasswordActivity"
            android:label="@string/title_activity_password"
            android:theme="@style/MyTheme" >
        </activity>
    </application>

</manifest>

First of all, when you change the name do it using the refactoring option in Android studio (right click on the package, and click rename). Then the reason you will still see the old package is that Android Studio has not detected any code changes, and is just giving you the package that is already built. You can change this by doing a project clean . Please comment if you have any issues

在此处输入图片说明

Click with right button on your com.randompasswordgenerator folder and go to

Refactor>Rename (Shift + F6), than change to whatever you like!!!

Don't forget to Rename others locations that you "call" your package name!

Good Luck!

You could also programmatically specify the applicationId

android {
    ...
    defaultConfig {
        applicationId 'com.passwordgen'
    }
}

this changes the outputted code but doesn't affect the original source directory paths

Changing Project Name

I am saying what has worked for me.

I have tried to change the Project Name/App name in Android Studio with Refactor option. But "Can not change project name/root folder" pop up comes.

Then I closed the project in android stuio (Android Studio is still not closed), then i changed the project folder name from DipCalculator to DipCalculator2 . Then I changed package name in all java code occurrences in app/src. Then app/build.gradle, app/app.iml file. changing project name in build.gradle file . I did not distrubed any other folders/files other than what i mentioned

Then I reopened the project from Android Studio, Then Build Synch. Then i build the apk & run it on my phone. New installation showed new app name DipCalculator2 instead of DipCalculator .

Just clean project then go to Manifexst.XML and search where says android label="@/String_appname" and delete it. for example : android label="NEW" regards!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM