是否有办法更改Flutter项目的Package Name ?
我想在flutter项目中更改包名和应用名。
是否有办法更改Flutter项目的Package Name ?
我想在flutter项目中更改包名和应用名。
当前回答
从Android Studio 4.1.3开始,更改包名再简单不过了。
如果您不使用Firebase或任何其他外部服务,只需更改以下文件中的包名称:
在构建中。Gradle (app)文件 在Manifest文件中(主文件、调试文件和概要文件) 包导入在代码文件(Android Studio。将处理更改)
注意:还要更改目录名(在Kotlin或Java下)。
如果您使用Firebase或任何其他外部服务,您也需要更改那里的包名称。
其他回答
Android应用名称
修改AndroidManifest.xml文件中的标签名称:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="TheNameOfYourApp"
软件包名称
修改AndroidManifest.xml文件中的包名(其中3个文件夹:main, debug和profile,根据你想部署的环境):
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name">
在你的构建中也是如此。应用程序文件夹内的Gradle文件
defaultConfig {
applicationId "your.package.name"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
最后,更改MainActivity.java类中的包(如果MainActivity.java不可用,请检查MainActivity.kt)
package your.package.name;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
修改目录名称:
来自:
android\app\src\main\java\com\example\name
To:
android\app\src\main\java\your\package\name
编辑:12月18日
对于包名,只需在build build中更改即可。它只
defaultConfig {
applicationId "your.package.name"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
为iOS
从你的信息中更改包标识符。plist文件在你的ios/Runner目录。
<key>CFBundleIdentifier</key>
<string>com.your.packagename</string>
更新
为了避免重命名包和包标识符,你可以在终端中使用以下命令启动你的项目:
flutter create --org com.yourdomain appname
这是我如何重命名包为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
首先,在终端中运行这个程序 Dart pub全局激活重命名 在Flutter项目根目录中运行此命令 bundleId .company.appname——目标android
这就是所有的东西,现在你改变了你的包名:)
手动更改名称似乎不起作用,抛出gradle错误,在我的情况下,它确实抛出错误。
所以我通常会创建一个新的颤振项目
我使用下面提到的命令创建一个新的扑动应用程序
flutter create --org com.yourdomain appname
您的项目的包名将是-> com.yourdomain.appname
如果你只是想保持你的包名称为com。然后对Appname进行如下更改
flutter create --org com appname
为android添加Java而不是kotlin添加-a Java
flutter create -a java --org com.yourdomain appname
EDIT
如果您已经创建了一个项目,您可以使用change_app_package_name包来更改包的名称。
flutter pub run change_app_package_name:main com.package.appname
即使我的答案不会被接受为正确答案,我只是觉得所有这些答案导致我有更多的问题,这里是我如何解决它
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。