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

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


当前回答

对于像我这样不喜欢更改特定文件的人,我使用了https://pub.dev/packages/rename。

使用这个,你只需要在你的终端上运行这些命令,你的应用名称和标识符就会被改变。酒吧全球运营

正在安装:pub全局激活重命名

然后,在颤振项目根目录中运行此命令。

pub全局运行rename——bundleId com.example.android.app——目标android

其他回答

根据官方的flutter文档,您只需要在app/build中更改ApplicationId。gradle目录。然后你只需要构建你的apk, manifest文件的包名将根据你在build.gradle中更改的ApplicationId进行更改。由于在构建apk和谷歌播放时的颤扑,都考虑从build.gradle中的ApplicationId。这个解决方案对我很有效。

来源:官方文件

使用此插件(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

在Vs Code,我所做的是搜索和替换它,它工作!就像一个符咒。

com.example.appName

重新启动vs代码。

这是我如何重命名包为ios和android

Go to build.gradle in app module and rename applicationId "com.company.name" Go to Manifest.xml in app/src/main and rename package="com.company.name" and android:label="App Name" Go to Manifest.xml in app/src/debug and rename package="com.company.name" Go to Manifest.xml in app/src/profile and rename package="com.company.name" Go to app/src/main/kotlin/com/something/something/MainActivity.kt and rename package="com.company.name" Go to app/src/main/kotlin/ and rename each directory so that the structure looks like app/src/main/kotlin/com/company/name/ Go to pubspec.yaml in your project and change name: something to name: name, example :- if package name is com.abc.xyz the name: xyz Go to each dart file in lib folder and rename the imports to the modified name. Open XCode and open the runner file and click on Runner in project explorer. Go to General -> double click on Bundle Identifier -> rename it to com.company.name Go to Info.plist click on Bundle name -> rename it to your App Name. close everything -> go to your flutter project and run this command in terminal flutter clean

我认为这不是解决这个问题的正确办法。但是您可以用您想要的包名创建一个新项目,然后从现有项目中将所有源文件复制到新项目中。

**注意:你也必须复制pubspec的所有内容。在firebase和其他api的情况下,这个解决方案可能有点冗长。