2023年2月14日星期二

解决Flutter上架Google Play提示Version code 1 has already been used. Try another version code.

 首先我们得搞清楚Flutter中的版本是如何管理的。


Flutter打包的版本名和版本号默认是从pubspec.yaml中的version读取的。我们只需要更新它的值就可以了。


格式为


version:A.B.C+X


对于Android的版本来说,版本号的管理在app/build.gradle中配置。


android{

    defaultConfig {

        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).

        applicationId "com.exmaple.demo"

        minSdkVersion 21

        targetSdkVersion 31

        versionCode flutterVersionCode.toInteger()

        versionName flutterVersionName

    }

}


A.B.C代表了verisonName,比如默认初始值为1.0.0.

X代表versionCode,默认值从1开始,依次累加。

默认App的versionName为1.0.0,versionCode为1。


解决方案

因为对于默认的versionName来说,后面不加上versionCode,versionCode就会默认为1.所以1.0.0和1.0.0+1是没有任何区别的。


我们只需要在versionCode后面加上更大的数字即可。比如+2.


name: flutter_demo

description: A new Flutter application for Flutter demo


# The following line prevents the package from being accidentally published to

# pub.dev using `pub publish`. This is preferred for private packages.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev


# 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.

# In Android, build-name is used as versionName while build-number used as versionCode.

# Read more about Android versioning at https://developer.android.com/studio/publish/versioning

# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.

# Read more about iOS versioning at

# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

# 1更改为2

version: 1.0.0+2

沒有留言:

發佈留言