I’m working on a Flutter project with multiple flavors (dev and prod). The APK builds successfully into the correct directory for the flavor, but when launching, the system looks for the APK in a different, non-flavor-specific path and fails to find it.
Here’s the error message I get:
✓ Built build/host/outputs/apk/dev/debug/app-dev-debug.apk.
"build/host/outputs/apk/debug/app-dev-debug.apk" does not exist.
Error launching application on sdk gphone64 x86 64.
My Setup:
build.gradle:
def flutterPluginVersion = 'managed'
apply plugin: 'com.android.application'
android {
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace "com.******.host"
}
compileSdk 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.******.host"
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
flavorDimensions "app"
productFlavors {
dev {
dimension "app"
applicationId "com.******.host"
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
prod {
dimension "app"
applicationId "com.******.host"
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
}
buildTypes {
profile {
initWith debug
}
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
buildDir = new File(rootProject.projectDir, "../build/host")
dependencies {
implementation project(':flutter')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
Command to run:
flutter run –flavor dev -t lib/dev_application.dart
flutter run –flavor prod -t lib/prod_application.dart
I also tried:
flutter run –flavor dev –debug -t lib/dev_application.dart
flutter run –flavor prod –debug -t lib/prod_application.dart
Question:
How can I ensure that the APK is found in the correct flavor-specific directory during the launch process? Is there any configuration I’m missing or any steps I need to follow to align the build output paths with the launch process?