Hadeed, my offline gym log, is a Flutter app. I upgraded it to Flutter 3.50.0, Android Gradle Plugin 9.3.1 and Gradle 9.5.0, and the Android build failed on configuration with this error:
Library projects cannot set applicationIdSuffix
My app has no library projects. It has one app module, and the only applicationIdSuffix in it was on my own build types:
buildTypes {
debug {
applicationIdSuffix = ".dev"
}
getByName("profile") {
applicationIdSuffix = ".profile"
}
}
Both suffixes exist for the same reason. A test build with its own package id installs next to the Play build instead of replacing it. Replacing it would mean uninstalling the Play build first, and that deletes the user's training log. So I wanted to keep them.
Where the library comes from
The "library projects" are your Flutter plugins. Each plugin with Android code (share_plus, flutter_local_notifications and so on) is its own Gradle library module, and Flutter's Gradle plugin gives each of them the app's build types so variants line up. Here's the code, from packages/flutter_tools/gradle/src/main/kotlin/plugins/PluginHandler.kt in Flutter 3.50.0:
// Copy the app project's build types onto the plugin project so that its variants
// resolve. These are `initWith` copies, not live aliases ...
val pluginProjectBuildTypes = getAndroidExtension(pluginProject).buildTypes
getAndroidExtension(project).buildTypes.forEach { appBuildType ->
if (pluginProjectBuildTypes.findByName(appBuildType.name) == null) {
pluginProjectBuildTypes.create(appBuildType.name) {
initWith(appBuildType)
// ...
}
}
}
initWith copies the build type's properties, applicationIdSuffix included. AGP 9 doesn't allow that property on a library build type, so the first plugin to receive the copy fails the build.
Why debug was fine and profile wasn't
Look at the findByName(...) == null check. Flutter only copies build types that the plugin doesn't already have. Every Android library module has debug and release out of the box, so those are never copied, and the .dev suffix on debug never reaches a plugin.
profile is a Flutter build type, not an Android default. Plugins don't have it, so Flutter copies it with initWith, suffix and all. That's why the same line worked on debug and broke on profile. The same goes for any custom build type you add, like staging or qa: put applicationIdSuffix on it and every plugin inherits it.
The fix: set the id on the variant
Don't put the suffix on the build type. Set the application id on the variant with the AGP variant API. Variants belong to the app module, so plugins never see it:
android {
buildTypes {
debug {
applicationIdSuffix = ".dev" // safe: libraries already have debug
}
getByName("profile") {
versionNameSuffix = "-profile" // no applicationIdSuffix here
}
}
}
androidComponents {
onVariants(selector().withBuildType("profile")) { variant ->
variant.applicationId.set("com.example.app.profile")
}
}
That goes at the top level of android/app/build.gradle.kts, next to the android { } block. versionNameSuffix is fine to leave on the build type. Only applicationIdSuffix is rejected.
If you'd rather not hardcode the full id, you can read the base id from android.defaultConfig.applicationId and append .profile to it.
Check it worked
-
flutter build apk --profilefinishes configuration without the error. -
aapt2 dump badging build/app/outputs/flutter-apk/app-profile.apk | head -1showspackage: name='com.example.app.profile'. - Install it next to the store build. Both appear on the phone, and the store build's data is still there.
The rest of the same upgrade
Two other things from the same upgrade cost me time, so I'll mention them:
- Gradle version floor. I was on Gradle 8.14, which is below what Flutter 3.50 asks for. Check the toolchain minimums before bumping the SDK, not after the first red build.
-
in_app_update 5.x. It dropped its own Kotlin plugin and relies on AGP's built-in Kotlin. My app keeps built-in Kotlin off (
android.builtInKotlin=false) because other plugins still applykotlin-android, so in_app_update 5 compiled to nothing and the build failed onInAppUpdatePlugin. I pinned it to^4.2.5until the other plugins catch up.
Running flutter analyze and the full test suite after each step (SDK, then packages, then code) meant each break showed up next to the step that caused it.
Top comments (0)