如何在android studio中更改包名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25848046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:45:26  来源:igfitidea点击:

How to change package name in android studio?

androidandroid-studiogoogle-play

提问by Thaej Sooriya

I have made an app and it is my very first app so when I started coding, I left the package name as com.example.stuff and now when I try to upload to the play store it wont let me due to the package name. I have tried refactor-> rename the package name and changed it in the AndroidManifst.xml then I tried to upload again. I am once again left with the same message time after time.

我制作了一个应用程序,这是我的第一个应用程序,所以当我开始编码时,我将包名称保留为 com.example.stuff,现在当我尝试上传到 Play 商店时,由于包名称,它不会让我使用。我尝试过重构-> 重命名包名称并在 AndroidManifst.xml 中更改它,然后我尝试再次上传。我一次又一次地收到同样的信息。

I appreciate any help and thanks in advance. :)

我感谢任何帮助并提前致谢。:)

回答by Mehmet

First click once on your package and then click setting icon on Android Studio.

首先单击一次您的包,然后单击 Android Studio 上的设置图标。

Close/Unselect Compact Empty Middle Packages

关闭/取消选择Compact Empty Middle Package

Then, right click your package and rename it.

然后,右键单击您的包并重命名它。

Thats all.

就这样。

enter image description here

在此处输入图片说明

回答by Scott Barta

In projects that use the Gradle build system, what you want to change is the applicationIdin the build.gradle file. The build system uses this value to override anything specified by hand in the manifest file when it does the manifest merge and build.

在使用 Gradle 构建系统的项目中,您要更改的是applicationIdbuild.gradle 文件中的 。构建系统在执行清单合并和构建时使用此值来覆盖清单文件中手动指定的任何内容。

For example, your module's build.gradle file looks something like this:

例如,您的模块的 build.gradle 文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        // CHANGE THE APPLICATION ID BELOW
        applicationId "com.example.fred.myapplication"
        minSdkVersion 10
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
}

applicationIdis the name the build system uses for the property that eventually gets written to the packageattribute of the manifesttag in the manifest file. It was renamed to prevent confusion with the Java package name (which you have also tried to modify), which has nothing to do with it.

applicationId是构建系统用于最终写入清单文件中标记package属性的属性的名称manifest。它被重命名以防止与 Java 包名称(您也曾尝试修改)混淆,后者与它无关。

回答by hwat

It can be done very easily in one step. You don't have to touch AndroidManifest. Instead do the following:

只需一步即可轻松完成。您不必触摸 AndroidManifest。而是执行以下操作:

  1. right click on the root folder of your project.
  2. Click "Open Module Setting".
  3. Go to the Flavours tab.
  4. Change the applicationID to whatever package name you want. Press OK.
  1. 右键单击项目的根文件夹。
  2. 单击“打开模块设置”。
  3. 转到风味选项卡。
  4. 将 applicationID 更改为您想要的任何包名称。按确定。

回答by Sagar Pilkhwal

Another good method is: First create a new package with the desired name by right clicking on the java folder -> new -> package.

另一个好方法是:首先通过右键单击java文件夹->新建->包,创建一个具有所需名称的新包。

Then, select and drag all your classes to the new package. Android Studio will refactor the package name everywhere.

然后,选择所有类并将其拖到新包中。Android Studio 会在任何地方重构包名。

Finally, delete the old package.

最后,删除旧包。

or Look into this post

或查看这篇文章