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

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


当前回答

如果你不喜欢以这种方式改变文件,那么另一种方式是使用这个包。

https://pub.dev/packages/rename

rename --bundleId com.newpackage.appname
pub global run rename --appname "Your New App Name"

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

其他回答

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

简单的方法,在编辑器中搜索例如vs CODE your.package.name例如com.example.application通过所有文件。

3个AndroidManifest文件(profile, debug, main) 1 build.gradle 1 java 或者kt文件

这些会弹出

替换所有这些,瞧。如果你已经构建了你的项目,build目录中会弹出许多文件,你可以忽略这些文件,不需要更改它们

这是我如何重命名包为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

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

来源:官方文件

一步一步

在您首选的IDE中打开项目文件夹。 定位pubspec。Yaml文件在项目的根。 将以下行添加到pubspec中。yaml文件:

名称:< your_new_package_name >

在同一目录下,打开“android”文件夹。 打开app文件夹并找到构建。gradle文件。 用新的包名替换当前的包名。 打开ios文件夹。 定位跑步者。ios文件夹中的Xcodeproj文件。 打开信息。plist文件。 用新的包名替换当前的包名。 保存所有更改并关闭文件。 执行命令flutter clean。 最后,运行命令flutter pub get。