是否有办法更改Flutter项目的Package Name ?

我想在flutter项目中更改包名和应用名。


当前回答

使用此插件(2022年)

https://pub.dev/packages/change_app_package_name

使用

flutter pub run change_app_package_name:main com.new.package.name

Old Package Name: com.example.oldname
Updating build.gradle File
Updating Main Manifest file
Updating Debug Manifest file
Updating Profile Manifest file
Project is using kotlin
Updating MainActivity.kt
Creating New Directory Structure
Deleting old directories

其他回答

更新您必须将包名更改为所需的包名 五个位置。

1.) src/profile/AndroidManifest.xml
2.) src/debug/AndroidManifest.xml
3.) src/main/AdroidManifest.xml
4.) app/build.gradle
     build.gradle .
       defaultConfig {
           applicationId
       }
5.) MainActivity.java or MainActivity.kt on "package"

最后一步是运行颤振干净

从Android Studio 4.1.3开始,更改包名再简单不过了。

如果您不使用Firebase或任何其他外部服务,只需更改以下文件中的包名称:

在构建中。Gradle (app)文件 在Manifest文件中(主文件、调试文件和概要文件) 包导入在代码文件(Android Studio。将处理更改)

注意:还要更改目录名(在Kotlin或Java下)。

如果您使用Firebase或任何其他外部服务,您也需要更改那里的包名称。

将更改应用程序包名称添加到您的pubspec。dev_dependencies: section中的Yaml。

dev_dependencies:

change_app_package_name: ^ 1.1.0

更新附件 颤振酒吧得到

使用该命令修改包名。

颤振pub运行change_app_package_name:main com.new.package.name

其中com.new.package.name是你想要的应用程序的新包名,用任何你想要的名称替换它。

即使我的答案不会被接受为正确答案,我只是觉得所有这些答案导致我有更多的问题,这里是我如何解决它

Get Sublime Text (crazy, right? No, just follow my steps) Click on file and select open folder, then choose the folder of the project you are working on Now click on Find from the Tabs, and select find in files or just do Ctrl + Shift + F (for Windows users, for mac users you already know the drill) Now copy and paste exactly the name of the package you want to change in the Find section and paste in the replace section what you would like to replace the package name with. Click on FIND (do not click on REPLACE just yet). Now clicking on Find lists all available package name in your project which matches your search criteria, if you are satisfied with this then repeat from no. 3 but this time click on REPLACE. Rebuild your project and have fun

结论:一个简单的查找和替换程序就可以解决这个问题,我强烈推荐Sublime Text 3。

您可以通过谷歌:https://developer.android.com/studio/build/application-id.html查看此官方文档

应用程序ID应该在构建中更改。gradle,包名可以在AndroidManifest.xml中修改。

但是,在更改包名时应该谨慎。

另外,在重新上传应用程序时,应该小心,因为它与之前上传的应用程序的ID相匹配。