Version Code Error while Uploading Flutter Apk to Play Store - flutter

Play console is giving error "Use different Version Code".
I have tried everything. Changing the version code in the pubspec.yaml to 2.0.1+2. And then running pub get
Changing the version code in the local.properties file.
Flutter Clean and then build the release. Even then Play Console is giving error.

I Was also facing the same problem, and later got to know that my version code was defined statically in my build.gradle file.
Go To Android -> App -> build.gradle file
And To Change it from there Please check your build.gradle file, is the version Code coming from flutterVersionCode or is it defined statically?
defaultConfig {
//...
versionCode flutterVersionCode.toInteger() //See this line, is it same as mine or you have any static version Code set there which is causing the issue.
versionName flutterVersionName
}

Related

Where is flutter.compileSdkVersion?

While building flutter app, I am getting this error.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to C:\flutter\projects\my_app\android\app\build.gradle:
android {
compileSdkVersion 33
...
}
However, in my build.gradle I have :
android {
compileSdkVersion flutter.compileSdkVersion
...
}
But I am unable to find the location where flutter.compileSdkVersion is defined. Any idea where is this defined? I have already run flutter upgrade and flutter --version returns Flutter 3.0.5.
To strictly answer your question, the setting comes from the flutter installation directory here:
<flutter-installation>\packages\flutter_tools\gradle\flutter.gradle
Some options to change the setting:
If you want to have the settings gathered in one place, then you could set it in the file local.properties as:
flutter.compileSdkVersion=33
And you change in your build.gradle in the following way:
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
...
}
or (obviously) just set the version direct as:
android {
compileSdkVersion 33
...
}
Every flutter version has a compiledSdkVersion property along with others. As of Flutter 3.3.8, it is 31.
You can access the code here
https://chromium.googlesource.com/external/github.com/flutter/flutter/+/refs/heads/dev/packages/flutter_tools/gradle/flutter.gradle#33
In future it might be more than 33. In case you hardcode value as 33, flutter might stop building with errors.
So the solution should be
compileSdkVersion Math.max(flutter.compileSdkVersion, 33)
now, in future if flutter changes the property to say 35, your code won't break.
Open the android folder.
open the App folder.
open the build.gradle from app folder.
flutter.compileSdkVersion is the default version that defaults to installed flutter version configs.
You can replace flutter.compileSdkVersion to your own custom version.
yes, and there you need to change it.
replace:
android {
compileSdkVersion flutter.compileSdkVersion
...
}
with this:
android {
compileSdkVersion 33
...
}
flutter.compileSdkVersion just the default one got from the flutter sdk.

Share_plus plugin - Error: Call requires API level 22 (current min is 16): android.content.Intent#createChooser [NewApi]

My flutter version: Flutter 3.0.0
Gradle version: Gradle 7.2
when I run .../android$ ./gradlew clean and then .../android$ ./gradlew build -warning-mode all in terminal, I get the following error:
> Task :share_plus:lintDebug FAILED
Lint found 4 errors, 3 warnings. First failure:
/home/my-name/.pub-cache/hosted/pub.dartlang.org/share_plus-6.2.0/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt:68: Error: Call requires API level 22 (current min is 16): android.content.Intent#createChooser [NewApi]
Intent.createChooser(
I changed minSdkVersion like the following but it is still not working.
android/app/build.gradle:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.citymarker"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
android/local.properties:
sdk.dir=/home/my-name/Android/Sdk
flutter.sdk=/home/thiago/development/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=23
flutter.targetSdkVersion=33
flutter.compileSdkVersion=33
I tried everything I could, but nothing is working.
I solved using a lower version of share_plus plugin. Just add the below line in your pubspec.yaml under dependencies:
share_plus: 4.0.2
I don't know yet why the error was happening even after changing minSdkVersion to 23. If someone has an answer, please, share with us.
under External Libraries you can find all the libraries u r using including share_plus (these are the files generated when u run 'flutter pub get'). U need to update share_plus/android/build.gradle with minSdkVersion 23, and it should build.enter image description here

Flutter error: Execution failed for task ':app:compileDebugJavaWithJavac'

I try run on android and return this error.
I Aredy tried:
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
build.gradle:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
my pubspec.yaml:
flutter_facebook_login: ^3.0.0
firebase_database: ^3.1.0
firebase_auth: ^0.15.0+1
cloud_firestore: ^0.12.11
url_launcher: ^5.2.7
google_maps_flutter: ^0.5.21+12
image_picker: ^0.6.2+1
firebase_storage: ^3.0.8
intl: ^0.16.0
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 35s The built failed likely due to AndroidX
incompatibilities in a plugin. The tool is about to try using Jetfier
to solve the incompatibility. Building plugin cloud_firestore... The
plugin cloud_firestore could not be built due to the issue above.
SOLUTION:
When you created the new project, did you select "androidX"? And are those versions the latest versions? (meaning, androidX compatible/requiring). if not sure, create a new project and make sure to select androidX, and change the sdk settings to 23/29 as above.
Edit: Solution was a combination of creating a new project with AndroidX selected and add the proper SDK versions to the gradle file. Possibly with using correct dependency versions.
To migrate to AndroidX, you need to set the SDK versions to 21 or higher. I recommend 23 because that removes some other issues as well.
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example"
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I recently encountered this error using Flutter 2.2.2, None of the above solutions worked for me.
First try basic commands like:
cd android && ./gradlew clean
flutter clean
If it doesn't work:
set distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip in android/gradle/wrapper/gradle-wrapper.properties
if your gradle version is <= 6.7 (refer gradle issue)
Try basic commands and build again!
Solution
flutter clean
delete android/.gradle and run
revert pubspec.lock and flutter pub get
flutter run
Change compileSdkVersion value to flutter.compileSdkVersion
also change minSdkVersion,targetSdkVersion values as shown below
android {
compileSdkVersion flutter.compileSdkVersion
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.octs"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
This worked for me.
None of answers above helped me. I use IntelliJ Idea as an IDE instead of Android Studio (because I develop other modules in other langs, not only Flutter app). I was able to run ./gradlew :app:compileDebugJavaWithJavac from command line, but flutter run failed. After long time I've realized that Flutter uses Android Studio to let it build android app. So if you use IntelliJ Idea, do check what Java you use not only in Idea (I use Java 11), but what Java you use in Android Studio! (mine AS used Java 8). After changing to Java 11, problem was solved.
I solved my problem by changing the version (reduced the gradle version), which caused me another problem, but related to one API and Kotlin plugin. Since I cannot delete Kotlin I took out the API and it came to life again! thanks for your help here!
Try this package flutter_stripe: ^3.2.0

Flutter appbundle building using older version

I want to upload the second version of my Flutter app to the internal test channel on Google Play (I am just working with the Android version for now).
I could upload the first version 1.0.0+1 but when trying to upload the second version 1.0.1+2 Google Play Console is rejecting my appbundle with error message
You need to use a different version code for your APK because you already have one with version code 1.
I have already tried the sequence:
flutter clean to delete build and temp folders.
Modifying version line on pubspec.yaml from 1.0.0+1 to 1.0.1+2.
flutter pub get to rebuild flutter needed files.
flutter build appbundle to get the bundle built.
Since I have been already able to build and publish the first version of the app I assume that the rest of the build configuration is OK.
Most of the solutions aim to clean project, modify pubspec.yaml and then rebuild but this seems not to be working for me.
EDIT:
tried to modify build.gradle file using values flutterVersionName = '1.0.1' and flutterVersionCode = '2' and I am still getting an appbundle with versionCode 1.
Android app version code and version name are defined in android/app/build.gradle. Take a look at this file and check if these lines are included
...
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
...
defaultConfig {
applicationId "net.myapp"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger() //<-this line defines versionCode
versionName flutterVersionName
...
If everything is ok, take a look at android/local.properties file. This file is updated when Flutter build the app. It should have these lines, generated from your pubspec.yaml data:
flutter.versionName=1.1.1
flutter.versionCode=9
If both files are ok, run a flutter build apk to regenerate local.properties data.
Found a workaround good enough and that is building the appbundle not using Flutter sdk, but using Android Studio.
In order to achieve that do the following:
Open Android Studio > Open android project (android folder in your Flutter project)
Then modify your app level build.gradle as follows:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "<YOUR_APP_ID>"
minSdkVersion 21
targetSdkVersion 28
versionCode 2 // Manually add your desired version code
versionName "1.0.1" // Manually add your desired version name
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Then go to Build > Generate Signed Bundle / APK... to generate your bundle or APK as if you were building a native app (further instructions to generate a signed app bundle can be found here
Please note that this does not fully solve the issue since the bundle still cannot be correctly generated using Flutter sdk.

Flutter failed to compile apk: Finished with error: Gradle task assembleDebug failed with exit code 1

Flutter failed to compile an apk. I am not sure if this has something to do with AndroidX or something.
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Finished with error: Gradle task assembleDebug failed with exit code 1
I ran flutter clean. I also ran flutter run -v. This is what happened: https://1drv.ms/t/s!An3OLJ7n0CjEku1SBrSABWab901z3Q
(I have used an external file locker because the stack trace is too large for the Stack Overflow editor).
This issue is similar to https://github.com/flutter/flutter/issues/30634
try follow steps:1. in gradle-wrapper.properties, downgrade from 5.1.1 to 4.10.2.2. int root/build.gradle, change android gradle version into 'com.android.tools.build:gradle:3.3.2'
Hope it is useful
It is common after migration to androidX.
If you followed recommended route from here:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
Try this:
Check with steps in "not recommended" way in above tutorial if every listed files is same as in your project, especially :
in root/android/gradle/wrapper/gradle-wrapper.properties set distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip (probably you have version 5.1.1 )
in root/android/build.gradle, set
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
check if in root/android/app/build.gradle SDK version is set to minimum 28 for:
compileSdkVersion 28 and targetSdkVersion 28
If you still get error then here is what helped me:
delete .gradle and .m2 folders from $HOME directory, as well with in app folders: root/android/.gradle and root/build
flutter doctor
flutter clean
flutter packages pub cache clean
if you changed (as me) app icon then run:
flutter packages pub run flutter_launcher_icons:main
it will render icons for app - without it print same error with gradle..
Invalidate caches in Android Studio "File" > "Invalidate Caches / Restart..."
If nothing from above works open android project as module
(you can do it by opening any file inside android folder for example manifest, then bar above code will shows with link to "Open for Editing in Android Studio", more here https://flutter.dev/docs/development/tools/android-studio )
Then click on gradle tab on the left and compile app - should show now more detailed error message.
Ok so here is your fix, open android sdk settings and uncheck Hide Obsolete Packages and in sdk tools, Check Android SDK Tools (Obsolete) than click ok/apply. It will download old SDK. Than Restart the IDE, Run default flutter program on emulator. This error occurs because flutter isn't compatible with latest Android SDK so you have yo manually install old SDK in Android studio.
Try running "flutter clean" in the project. If it doesn't work, please paste the output after running "flutter run -v".
In the debug mode applications worked well, but when I tried to build a release version, it had this error.
"Flutter doctor -v" was ok.
Made flutter clean.
Checked all AndroidX recommendations, used all latest versions of packages.
Checked android/app/fourpillarsappru1.keystore settings.
Finally the decision was use build in in Android Studio commands instead of command line "flutter build apk".
So, the decision in my case was:
Open build.gradle for editing in Android Studio
Choose Build / Generate Signed Bundle/APK
I had the same problem and solve the error by running flutter doctor --android-licenses and accept all licenses agreement.
I hope it will help
The Solution that works for me and makes the most sense CLEAN CACHE
Enter Command below
--> flutter packages pub cache clean
Downgrading the build gradle version in gradle-wrapper.properties from 5.1.1 to 4.10.2 worked for me.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
Dependencies in project: build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.0.1'
}
module: build.gradle
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 versionPropertiesFile = rootProject.file("../version.properties")
def versionProperties = new Properties()
versionProperties.load(new FileInputStream(versionPropertiesFile))
def flutterVersionCode = versionProperties.getProperty('flutter.versionCode')
def flutterVersionName = versionProperties.getProperty('flutter.versionName')
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.lok.sewa"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'
Try checking your key.properties file. There might be error in key path, keyAlias or passwords. The error by key errors is not traceable.
This solution worked for me
It is android problems only so
Open in Android Studio
and pick Flutter->Open module in Android Studio
menu Build->Build Bundle(s) / APKs->Build Bundles.
My code contain keystore info in build.gradle,but we don't have keystore file in our git repository.My colleague uploaded his local keystore file and the problem was solved.
I just simply fixed it by changing the minSdkVersion . Just try minSdkVersion 19 or 21. It will fix.
compileSdkVersion 29
minSdkVersion 19
targetSdkVersion 29