Reputation: 1318
I've created 3 buildTypes at my android project:
buildTypes {
release {
signingConfig signingConfigs.release
resValue "string", "app_name", "AppName"
}
debug {
applicationIdSuffix ".debug"
resValue "string", "app_name", "AppName - DEV"
}
staging {
initWith release
matchingFallbacks = ['release']
applicationIdSuffix ".debug"
}
}
I would like to assemble my staging build type, so I ran "flutter build apk --staging", but flutter can't find that option:
Could not find an option named "staging".
Seems that Flutter build apk command "flutter build apk" supports only 3 types : debug, profile, release; and in case of using custom buildType - there's no support for that.
Is it possible to build an apk of custom BuildType?
Upvotes: 3
Views: 8068
Reputation: 713
If you don't actually need it to be a build type, you could use Flutter's supports for defining properties in Gradle like this:
flutter run --release --android-project-arg staging=1
Then in Gradle, you can detect this property and change things depending on it:
buildTypes {
release {
signingConfig signingConfigs.release
resValue "string", "app_name", "AppName"
if (project.hasProperty("staging")) {
matchingFallbacks = ["release"]
applicationIdSuffix ".debug"
}
}
debug {
applicationIdSuffix ".debug"
resValue "string", "app_name", "AppName - DEV"
}
}
Adding this argument to your launch configuration is also easy, in VS Code for example just add this to .vscode/launch.json
:
"args": ["--android-project-arg", "staging=1"]
I was having a similar issue that I tried to solve with build types or flavors, but Flutter's support on this is very limiting at the moment. I ended up using a property like this.
Upvotes: 1
Reputation: 1
My problem was starting a build type custom.
This code (see "preprod") worked for me (Flutter 3.0.4):
command line: flutter run --flavor preprod --release
signingConfigs {
debug {
storeFile file('../keystores/debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
releasetest {
storeFile file('../keystores/releaseTest-keystore.jks')
storePassword 'releaseTest'
keyAlias 'releaseTest'
keyPassword 'releaseTest'
}
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "flavor-type"
productFlavors {
dev {
dimension "flavor-type"
applicationIdSuffix ".dev"
}
preprod {
dimension "flavor-type"
buildTypes.release.signingConfig signingConfigs.releasetest
}
prod {
dimension "flavor-type"
}
}
Upvotes: 0
Reputation: 21
One solution is to use Android's own Gradle build tasks instead of using Flutter commands.
cd android/
./gradlew app:build
Then after a succesfull build you should be able to find an apk for each buildType in build/app/outputs/apk/
.
Upvotes: 1
Reputation: 56
I have a solution to this problem,open $flutterRoot/packages/flutter_tools/gradle/flutter.gradle
find project.android.buildTypes
add your buildtypes to this block, then back to your android project,invalidata cache/restart.
Upvotes: 0
Reputation: 1318
I ended up using productFlavors:
flavorDimensions 'app'
productFlavors {
dev {
dimension "app"
resValue "string", "app_name", "AppName - DEV"
applicationIdSuffix ".debug"
}
staging {
dimension "app"
resValue "string", "app_name", "AppName - DEV"
applicationIdSuffix ".debug"
}
prod {
dimension "app"
resValue "string", "app_name", "AppName"
}
}
Upvotes: 4