我能够构建应用程序的发行版并上传到Play商店,现在我想对其进行更新,并且需要更改versionCode
。但是,当我查看<android/app/build.gradle>
时,表示版本应该是整数的部分现在类似于flutterVersionCode.toInteger()
和versionName
flutterVersionName
,这对我和我不知道从哪里更改它。
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
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.")
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.someApp"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//implementation 'com.google.firebase:firebase-core:15.0.2'
//compile 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-core:15.0.2'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:2)
int generateVersionCode(String versionName) {
def parts = versionName.split("\\.").collect { it.toInteger() }
return parts[0] * 10000 + parts[1] * 100 + parts[2]
}
这是从他的flutterVersionName
生成版本的好方法
defaultConfig {
[...]
versionCode generateVersionCode(flutterVersionName)
versionName flutterVersionName
}
答案 1 :(得分:1)
您不需要手动修改build.gradle。
打开您的pubspec.yaml
,您会发现一个类似这样的条目:
version: 1.0.0+1
Flutter使用语义版本控制,因此您需要修改该条目:
version: 1.0.1+2
在这种情况下,版本名称将为1.0.1
,版本代码将为2