I wonder if it is possible to set String placeholder for versionCode in android.defaultConfig.
We run a build machine that should replace all <REPLACE> places with original values but versionCode excepts integer only.
Something like:
android {
compileSdkVersion 26
defaultConfig {
targetSdkVersion 26
minSdkVersion 14
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode "<REPLACE_VERSION_CODE>"
versionName "<REPLACE_VERSION_NMAE>"
Any ideas how to make it work?
So far I left versionCode -99999 but I look for more gentle solution
How about creating a variable in the gradle file and set it to some default value (e.g -99999) that can be replaced by your build machine.
For example
android {
compileSdkVersion 26
def version_code = -99999
defaultConfig {
targetSdkVersion 26
minSdkVersion 14
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode version_code
versionName "<REPLACE_VERSION_NMAE>"
}
}
This way you have a readable text (not int) on the versionCode line.
Related
Within ../android/app/build.gradle, there is a section that looks like this:
android {
defaultConfig {
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
Now, flutter.minSdkVersion seems to be a variable located in which file within my project?
It is the default values flutter takes.
You should updates these as per needed. For latest flutter android build, it should be
android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
You have to go to \android\local.properties
Then add
flutter.minSdkVersion = 26 // the version is up to your needs.
flutter.targetSdkVersion = 32
After that return to defaultConfig of build.gradle and call it like this :
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Don't forget to launch a flutter clean flutter pub get and then flutter run
In the old version, we could change it via android/app/build.gradle. Now it gives an error when we change it.
defaultConfig {
applicationId "com.example.manuel"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
There are those who fix this problem via local.properties, but this method does not work either.
sdk.dir=C:/Users/user/AppData/Local/Android/Sdk
flutter.sdk=C:\\src\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
you need to edit the build.gradle file in the new version as well. As follows;
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.manuel"
minSdkVersion 16 // <--- There minSdkVersion Content
targetSdkVersion 27 <--- There targetSdkVersion (is actually Max Sdk Version) Content
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
then rebuild the project and build it again.
I hope that will be useful.
I have created a new Flutter project, and this is how the minSdkVersion looks like in the app/build.gradle file:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Where is the value of flutter.minSdkVersion set?
Note that previously, that config value looked like the following:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Also, this is the content of the android/local.properties file:
sdk.dir=/Users/usernaem/Library/Android/sdk
flutter.sdk=/Users/username/flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1
As you can see, the value of flutter.minSdkVersion is not set there, but the project can be compiled and built successfully.
Where are the flutter.minSdkVersion and flutter.targetSdkVersion variables initialized?
P.S. related issue: https://github.com/flutter/flutter/issues/95533
Go to this file in your flutter extracted folder:
flutter/packages/flutter_tools/gradle/flutter.gradle
There you can find all static variables.
Put in your android/local.propertie file the variable:
Example:
flutter.minSdkVersion=21
And change in android/app/build.gradle
localProperties.getProperties('flutter.minSdkVersion') // flutter.minSdkVersion
Just replace flutter.minSdkVersion with your required value such as 19 like old style
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Follow the path /android/app/build.gradle
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.sample.com"
// 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 23
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
I am installing Android app with target sdk version android S in Android phone with Api level 30. My default config settings for app is like
compileSdkVersion 'android-S'
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 21
targetSdkVersion "S"
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
But when I install the apk in Emulator with Api Level 30 I am getting error as
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_OLDER_SDK
The application's minSdkVersion is newer than the device API level.
How to resolve this ? Which things need to be modified to make it working ?
targetSdkVersion "S"
Using a prelimary version the minSdkVersion becomes S too automatically.
Changing to this version worked
compileSdkVersion 'android-S'
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I have an android app with four flavours.Each flavor has his its own google-services.json file.
This file needs to be under /app structure.I found this approach to be working in various links:
productFlavors{
one{
applicationId 'com.flavor.one'
versionName '2.4.3'
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
versionCode 26
copy {
from 'src/one/'
include '*.json'
into '.'
}
}
two{
applicationId 'com.flavor.two'
versionName '1.0.13'
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
versionCode 26
copy {
from 'src/two/'
include '*.json'
into '.'
}
}
three{
applicationId 'com.flavor.three'
versionName '1.4.1'
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
versionCode 5
copy {
from 'src/three/'
include '*.json'
into '.'
}
}
four{
applicationId 'com.flavor.four'
versionName '1.4.1'
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
versionCode 5
}
}
But this approach is always copying the last json to app directory.Not copying the flavor based json.