The full error looks like this. The important part is the project name on the first line:
* What went wrong:
A problem occurred configuring project ':flutter_old_plugin'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Specify a namespace in the module's build file:
/Users/you/.pub-cache/hosted/pub.dev/flutter_old_plugin-1.2.0/android/build.gradle.
See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
Your own app is usually fine. Projects created by recent Flutter versions already set namespace in android/app/build.gradle(.kts). The problem is a package whose Android code was written before AGP 8.
Why it happens
Before AGP 8, an Android module’s package name came from the package="..." attribute in its AndroidManifest.xml. AGP 8 dropped that and requires a namespace line in the module’s build.gradle instead. When you upgrade AGP (Flutter 3.35 projects use 8.9.1, and Google Play’s target API rules push everyone there), every plugin without that line stops the build.
Step 1: find the plugin
The plugin name is in configuring project ':flutter_old_plugin', and the path points into your pub cache. Run:
flutter pub outdated
The Flutter package checker does the same from a pasted pubspec.yaml and also flags discontinued packages.
Step 2: update the plugin (the real fix)
Most popular plugins added namespace in 2023. Updating is usually enough:
flutter pub upgrade --major-versions
flutter clean
flutter pub get
--major-versions also raises the version constraints in your pubspec.yaml, so read the package changelog for breaking changes. If a package is discontinued, replace it with the alternative its pub.dev page suggests.
Step 3: a temporary patch, if no fixed version exists
Don’t edit the file inside .pub-cache. The change disappears the next time someone runs flutter pub get, including on CI. Instead, set the namespace for the plugin from your app’s top-level android/build.gradle.
Put this above the existing subprojects { project.evaluationDependsOn(":app") } block. If it goes below, Gradle reports that the project is already evaluated.
subprojects {
afterEvaluate { project ->
if (project.hasProperty("android") && project.android.namespace == null) {
project.android.namespace = project.group
}
}
}
Kotlin DSL (android/build.gradle.kts):
subprojects {
afterEvaluate {
extensions.findByType<com.android.build.gradle.BaseExtension>()?.let { android ->
if (android.namespace == null) {
android.namespace = group.toString()
}
}
}
}
Flutter plugins set group to their package name in their own build.gradle, so the namespace ends up matching the old manifest package. This is a patch, not a fix: also open an issue on the plugin’s repository, or fork it and depend on your fork through a git: dependency in pubspec.yaml.
Related errors in the same upgrade
AGP upgrades rarely fail on one error. The usual companions are:
- “Unsupported class file major version 65”: Gradle is older than your Java.
- “Requires a newer version of the Kotlin Gradle plugin”: your Kotlin is too old for a package.
The Flutter target API and Gradle checker gives the AGP, Gradle and targetSdk versions to move to together.
Frequently asked questions
What does "Namespace not specified" mean in Flutter?
Android Gradle Plugin 8 requires each Android module to declare a namespace in its build.gradle. An older Flutter plugin in your app still relies on the package attribute in its AndroidManifest.xml, so the build stops. The error names the plugin.
How do I fix "Namespace not specified" without downgrading AGP?
Update the plugin named in the error with flutter pub upgrade –major-versions. If no fixed version exists, set its namespace from your top-level android/build.gradle with an afterEvaluate block, or fork the plugin and add the namespace line yourself.
Should I downgrade the Android Gradle Plugin to avoid this?
No. Google Play’s yearly target API requirement needs a recent compileSdk, which needs a recent AGP. Downgrading only delays the same error, and Flutter 3.35 already warns below AGP 8.6.
Can I edit the plugin's build.gradle in the pub cache?
It works on your machine until the next flutter pub get or a CI build, which download the original files again. Patch it from your own android/build.gradle or use a fork instead.
Stuck on a build or a store release? I fix and maintain Flutter apps, or tell me about your project. More fixes: all Flutter answers.