简体   繁体   English

如何在Android Studio中更改我的应用程序的软件包名称?

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

I created a project in Android Studio. 我在Android Studio中创建了一个项目。 Android Studio generated a package name according to my app name. Android Studio根据我的应用程序名称生成了程序包名称。 But I don't want that name ( com.randompasswordgenerator ). 但我不要这个名字( com.randompasswordgenerator )。 So I found all the occurences of the package name and changed it to com.passwordgen . 因此,我找到了所有出现的软件包名称,并将其更改为com.passwordgen However, when I run the app, in the Run console, it still uses the old name: 但是,当我运行该应用程序时,在“ Run控制台中,它仍然使用旧名称:

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. 但是我发现的帖子使用Eclipse而不是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). 首先,在更改名称时,请使用Android Studio中的“重构”选项进行更改(右键单击该程序包,然后单击“重命名”)。 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. 然后,您仍然会看到旧软件包的原因是Android Studio尚未检测到任何代码更改,而只是向您提供了已构建的软件包。 You can change this by doing a project clean . 您可以通过project clean来更改此设置。 Please comment if you have any issues 如果您有任何问题,请发表评论

在此处输入图片说明

Click with right button on your com.randompasswordgenerator folder and go to com.randompasswordgenerator文件夹上单击右键,然后转到

Refactor>Rename (Shift + F6), than change to whatever you like!!! Refactor> Rename(Shift + F6),然后更改为您喜欢的任何内容!!!

Don't forget to Rename others locations that you "call" your package name! 别忘了重命名您“呼叫”软件包名称的其他位置!

Good Luck! 祝好运!

You could also programmatically specify the applicationId 您还可以以编程方式指定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. 我尝试使用Refactor选项更改Android Studio中的项目名称/应用程序名称。 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 . 然后,我在android stuio中关闭了项目(Android Studio仍未关闭),然后将项目文件夹名称从DipCalculatorDipCalculator2 Then I changed package name in all java code occurrences in app/src. 然后,我在app / src中所有Java代码中更改了包名。 Then app/build.gradle, app/app.iml file. 然后是app / build.gradle,app / app.iml文件。 changing project name in build.gradle file . 在build.gradle文件中更改项目名称 I did not distrubed any other folders/files other than what i mentioned 除了我提到的以外,我没有分散其他任何文件夹/文件

Then I reopened the project from Android Studio, Then Build Synch. 然后,我从Android Studio重新打开了项目,然后从Build Synch打开了。 Then i build the apk & run it on my phone. 然后,我构建apk并在手机上运行它。 New installation showed new app name DipCalculator2 instead of DipCalculator . 新安装显示了新的应用程序名称DipCalculator2而不是DipCalculator

Just clean project then go to Manifexst.XML and search where says android label="@/String_appname" and delete it. 只需清理项目,然后转到Manifexst.XML并搜索显示android label="@/String_appname"并将其删除。 for example : android label="NEW" regards! 例如: android label="NEW"问候!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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