通过 Android Studio 更改应用程序包名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22318722/
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
Change Application Package name through Android Studio
提问by Siddharth_Vyas
I am aware that this question is asked several times in SO. I have checked below answers posted but doesn't work for me :(
我知道这个问题在 SO 中被问了好几次。我检查了下面发布的答案,但对我不起作用:(
Currently, my application's package name is "com.example.test".I want to change this to "com.example.test.test1".So, I just changed the package name in my manifest file and build the app.
目前,我的应用程序的包名称是“ com.example.test”。我想将其更改为“ com.example.test.test1”。因此,我只是更改了清单文件中的包名称并构建了应用程序。
Now ,if I run both the applications seperately with above package names changed from manifest files into device than it should show me different applications.It shows me error as "Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]"
现在,如果我分别运行这两个应用程序,并将上述包名从清单文件更改为设备,那么它应该向我显示不同的应用程序。它显示我的错误为“失败 [INSTALL_FAILED_CONFLICTING_PROVIDER]”
As the package names are different, it should show me different applications in the device instead of overriding one app with other.Help me out.
由于包名称不同,它应该向我显示设备中的不同应用程序,而不是用其他应用程序覆盖一个应用程序。帮帮我。
Any help would be appreciated.Thanks
任何帮助将不胜感激。谢谢
回答by Subin Sebastian
The packageName
attribute is deprecated as of Android Studio V0.0.6 onward. To change the package name of the application, use applicationId
instead. Check the release notes here.
从packageName
Android Studio V0.0.6 开始,该属性已弃用。要更改应用程序的包名称,请applicationId
改用。在此处查看发行说明。
Change the applicationId and sync gradle.
更改 applicationId 并同步 gradle。
回答by pyus13
If your aim is to have the same application at two instance in the device, it is so easy to do using gradle. You don't need to change package name in the Manifest file, gradle will handle that during the build process for you and do all package renaming under the hood wherever required.
如果您的目标是在设备中的两个实例上使用相同的应用程序,那么使用 gradle 非常容易。您不需要在 Manifest 文件中更改包名称,gradle 将在构建过程中为您处理,并在需要的地方进行所有包重命名。
In order to achieve that you need to write a new product flavor for your app inside the main app module's build.gradle
file with a different application id(package name). Eg. if com.example.test
is your default package name of the app. You can have a different flavor of the same app with a different package name or knows as application id. produltFlavours can be defined inside android tag of your main module's build.gradle file like as shows below.
为了实现这一点,您需要在主应用程序模块的build.gradle
文件中为您的应用程序编写一个新的产品风格,并使用不同的应用程序 ID(包名称)。例如。ifcom.example.test
是应用程序的默认包名称。您可以使用不同的包名称或应用程序 id 来获得同一个应用程序的不同风格。produltFlavors 可以在主模块的 build.gradle 文件的 android 标签内定义,如下所示。
productFlavors {
app1 {
applicationId "com.example.test.test1"
}
}
Sync your project after making the changes. Now select the build variant from Build Variant
tab in left hand panel and hit run. Gradle script will handle all package renaming for you.
进行更改后同步您的项目。现在从Build Variant
左侧面板的选项卡中选择构建变体并点击运行。Gradle 脚本将为您处理所有包重命名。
Check this once for more details :
检查一次以获取更多详细信息:
回答by user3791771
What worked for me: 1. Right click package you want to change under java folder| 2. Refactor -> Rename| 3. Rename the package -> press "enter" -> press "Do Refactor"| 4. This updates all the files including the manifest
对我有用的方法: 1. 在 java 文件夹下右键单击要更改的包| 2.重构->重命名| 3.重命名包->按“回车”->按“Do Refactor”| 4. 这会更新包括清单在内的所有文件