如何设置 Flutter 应用程序的构建和版本号
How to set build and version number of Flutter app
如何在不进入 Android 和 iOS 设置的情况下设置 Flutter 应用程序的版本名称和版本代码?
在我的 pubspec.yaml 我有
version: 2.0.0
但我没有看到内部版本号的位置。
设置版本和构建号
您可以在pubspec.yaml中的同一位置更新版本名称和版本代码。只需用 +
符号将它们分开即可。例如:
version: 2.0.0+8
这意味着
- 版本名称是
2.0.0
- 版本号为
8
新项目的文档中对此进行了描述(但如果您正在处理旧项目,则可能已将其删除):
The following defines the version and build number for your application.
A version number is three numbers separated by dots, like 1.2.43
followed by an optional build number separated by a +.
Both the version and the builder number may be overridden in flutter
build by specifying --build-name and --build-number, respectively.
Read more about versioning at semver.org.
version: 1.0.0+1
重新启用自动版本控制
如果您的 Flutter 版本控制不再自动更新,请参阅 了解如何修复它。
另请参阅:
在Android中,构建名称用作版本名称,而构建编号用作版本代码。
在 https://developer.android.com/studio/publish/versioning 阅读有关 Android 版本控制的更多信息
在 iOS 中,build-name 用作 CFBundleShortVersionString,而 build-number 用作 CFBundleVersion。
在以下位置阅读有关 iOS 版本控制的更多信息
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
以上信息你可以在pubsec.yaml
中获取
您将在 android/app/build.gradle.
中找到 versionCode 或 buildnumber(对于 android)
defaultConfig {
applicationId "com.fabio.resturanto"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
您的 local.properties 文件中有 flutterVersionCode 和 flutterVersionName。这是特定于 Android build
两个iOS/Android版本都可以从pubspec.ymal
设置
version: 1.2.0+1
这里1.2.0是版本名+1是版本号
此处的更改 (pubspec.ymal) 将反映 Android 和 iOS 版本名称和版本代码。
感谢用户abion47 for finding and condensing the following answer from the article Versioning with Flutter。
Re-enabling 自动版本控制
默认情况下,Flutter 项目设置为在构建项目时根据 pubspec.yaml 中的版本设置自动更新 Android 和 iOS 设置。但是,如果您后来覆盖了这些设置,则可以通过执行以下操作 re-enable 该行为:
iOS
打开 ios/Runner/Info.plist 文件。将 CFBundleVersion 的值设置为 $(FLUTTER_BUILD_NUMBER) 并将 CFBundleShortVersionString 的值设置为 $(FLUTTER_BUILD_NAME)。该文件的 XML 应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
...
</dict>
...
Android
打开 android/app/build.gradle
文件。确保您在文件顶部正确加载 Flutter 属性:
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}
然后设置android.defaultConfig
部分,使versionName
为flutterVersionName
,versionCode
为flutterVersionCode.toInteger()
:
android {
...
defaultConfig {
...
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
对我有用的 (Android) :
- 更新 pubspec.yaml inside flutter project file for
versionname
and versioncode
.
- 运行
flutter pub get
在终端上。
- 运行 您在设备中的项目。
- 在 Andriod Studio 中打开 android 模块并检查
local.properties
更新 flutter.versionName
flutter.versionCode
个文件在 gradle 个文件夹中。
如果您使用的是 android studio,最简单的方法是将其从 local.properties
更改为
对我来说,我的版本是
version: 1.0.0+1
我把它改成了
version: 1.2.0+2
然后在终端
flutter build appbundle --build-name=1.2.0+2 --build-number=2
如何在不进入 Android 和 iOS 设置的情况下设置 Flutter 应用程序的版本名称和版本代码?
在我的 pubspec.yaml 我有
version: 2.0.0
但我没有看到内部版本号的位置。
设置版本和构建号
您可以在pubspec.yaml中的同一位置更新版本名称和版本代码。只需用 +
符号将它们分开即可。例如:
version: 2.0.0+8
这意味着
- 版本名称是
2.0.0
- 版本号为
8
新项目的文档中对此进行了描述(但如果您正在处理旧项目,则可能已将其删除):
The following defines the version and build number for your application. A version number is three numbers separated by dots, like 1.2.43 followed by an optional build number separated by a +. Both the version and the builder number may be overridden in flutter build by specifying --build-name and --build-number, respectively. Read more about versioning at semver.org.
version: 1.0.0+1
重新启用自动版本控制
如果您的 Flutter 版本控制不再自动更新,请参阅
另请参阅:
在Android中,构建名称用作版本名称,而构建编号用作版本代码。 在 https://developer.android.com/studio/publish/versioning 阅读有关 Android 版本控制的更多信息 在 iOS 中,build-name 用作 CFBundleShortVersionString,而 build-number 用作 CFBundleVersion。 在以下位置阅读有关 iOS 版本控制的更多信息 https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
以上信息你可以在pubsec.yaml
中获取您将在 android/app/build.gradle.
中找到 versionCode 或 buildnumber(对于 android)defaultConfig {
applicationId "com.fabio.resturanto"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
您的 local.properties 文件中有 flutterVersionCode 和 flutterVersionName。这是特定于 Android build
两个iOS/Android版本都可以从pubspec.ymal
设置version: 1.2.0+1
这里1.2.0是版本名+1是版本号 此处的更改 (pubspec.ymal) 将反映 Android 和 iOS 版本名称和版本代码。
感谢用户abion47 for finding and condensing the following answer from the article Versioning with Flutter。
Re-enabling 自动版本控制
默认情况下,Flutter 项目设置为在构建项目时根据 pubspec.yaml 中的版本设置自动更新 Android 和 iOS 设置。但是,如果您后来覆盖了这些设置,则可以通过执行以下操作 re-enable 该行为:
iOS
打开 ios/Runner/Info.plist 文件。将 CFBundleVersion 的值设置为 $(FLUTTER_BUILD_NUMBER) 并将 CFBundleShortVersionString 的值设置为 $(FLUTTER_BUILD_NAME)。该文件的 XML 应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
...
</dict>
...
Android
打开 android/app/build.gradle
文件。确保您在文件顶部正确加载 Flutter 属性:
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}
然后设置android.defaultConfig
部分,使versionName
为flutterVersionName
,versionCode
为flutterVersionCode.toInteger()
:
android {
...
defaultConfig {
...
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
对我有用的 (Android) :
- 更新 pubspec.yaml inside flutter project file for
versionname
andversioncode
. - 运行
flutter pub get
在终端上。 - 运行 您在设备中的项目。
- 在 Andriod Studio 中打开 android 模块并检查
local.properties
更新flutter.versionName
flutter.versionCode
个文件在 gradle 个文件夹中。
如果您使用的是 android studio,最简单的方法是将其从 local.properties
更改为对我来说,我的版本是
version: 1.0.0+1
我把它改成了
version: 1.2.0+2
然后在终端
flutter build appbundle --build-name=1.2.0+2 --build-number=2