plus_plugins
plus_plugins copied to clipboard
[Bug]: Wrong build number on android
Platform
Android 12
Plugin
package_info_plus
Version
1.4.3+1
Flutter SDK
3.0.5
Steps to reproduce
- My application version is set to version: 1.0.0+1 in pubspec.yaml
- I am using this code to get build number of my flutter application.
final info = await PackageInfo.fromPlatform();
print(info.buildNumber);
-
Out put with "flutter run --release" is 1
-
Out put with "flutter build apk --split-per-abi" is 1001
Out in 4 should be same as 3.
Code Sample
No response
Logs
NA
Flutter Doctor
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22000.856], locale en-IN)
• Flutter version 3.0.5 at C:\Users\Hardik\Documents\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (6 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at C:\Users\Hardik\AppData\Local\Android\sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.1.32210.238
• Windows 10 SDK version 10.0.20348.0
[√] Android Studio (version 2021.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
[√] VS Code (version 1.70.2)
• VS Code at C:\Users\Hardik\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.46.0
[√] Connected device (4 available)
• SM A515F (mobile) • RZ8N31RQE2L • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.856]
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.81
• Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.63
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Can you share your gradle file?
I am not sure why the reported version would be 1001 instead of 1, doesn't make any sense.
Here is my gradle file
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) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//android.buildTypes.release.ndk.debugSymbolLevel = 'FULL'
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 33 //flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.abc"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21 //flutter.minSdkVersion
targetSdkVersion 33 //flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
//useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
debugSymbolLevel 'FULL'
}
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.applovin:applovin-sdk:+'
implementation 'com.applovin.mediation:google-adapter:+'
implementation 'com.applovin.mediation:facebook-adapter:+'
}
oki, so it is just the normal flutterVersionCode.
The code that takes care of reading the build number is also very simple:
https://github.com/fluttercommunity/plus_plugins/blob/b3282a05ef894aae4b0321e79b2764ac956ff1a9/packages/package_info_plus/package_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.kt#L60
To me, it looks like an Android issue or something special with the Flutter build tool. If you can, try to implement the functionality by yourself and see if you still have the problem.
Platform
Android 12
Plugin
package_info_plus
Version
1.4.3+1
Flutter SDK
3.0.5
Steps to reproduce
- My application version is set to version: 1.0.0+1 in pubspec.yaml
- I am using this code to get build number of my flutter application.
final info = await PackageInfo.fromPlatform(); print(info.buildNumber);
- Out put with "flutter run --release" is 1
- Out put with "flutter build apk --split-per-abi" is 1001
Out in 4 should be same as 3.
Code Sample
No response
Logs
NA
Flutter Doctor
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22000.856], locale en-IN) • Flutter version 3.0.5 at C:\Users\Hardik\Documents\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (6 weeks ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at C:\Users\Hardik\AppData\Local\Android\sdk • Platform android-32, build-tools 32.1.0-rc1 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.1.32210.238 • Windows 10 SDK version 10.0.20348.0 [√] Android Studio (version 2021.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) [√] VS Code (version 1.70.2) • VS Code at C:\Users\Hardik\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.46.0 [√] Connected device (4 available) • SM A515F (mobile) • RZ8N31RQE2L • android-arm64 • Android 12 (API 31) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.856] • Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.81 • Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.63 [√] HTTP Host Availability • All required HTTP hosts are available • No issues found!
Translate from https://www.jianshu.com/p/5058eb7505d3
Flutter use android/app/build.gradle to pack apk, and it apply the flutter.gradle such as D:/flutter/packages/flutter_tools/gradle/flutter.gradle
About flutter.gradle 810 rows
def addFlutterDeps = { variant ->
if (shouldSplitPerAbi()) {
variant.outputs.each { output ->
def abiVersionCode = ABI_VERSION.get(output.getFilter(OutputFile.ABI))
if (abiVersionCode != null) {
output.versionCodeOverride =
abiVersionCode * 1000 + variant.versionCode
}
}
}
We know flutter will judge used 'split-per-abi' command whether or not, if used then select a version in ABI_VERSION and *1000 and plus build num.
The official explain at https://developer.android.com/studio/build/configure-apk-splits
What we should do is change the ABI_VERSION map as below
private static final Map ABI_VERSION = [
(ARCH_ARM32) : 0,
(ARCH_ARM64) : 0,
(ARCH_X86) : 0,
(ARCH_X86_64) : 0,
]
Closing as is it not an issue in the plugin, but Flutter tools.