Flutter "Namespace Not Specified" Error: The 4-Step Fix for AGP 8
What does "Namespace not specified" mean in a Flutter Android build?
It means one Android module in your build, almost always an older Flutter plugin, doesn't declare a namespace in its build.gradle file, and Android Gradle Plugin (AGP) 8 refuses to build without one. Google's AGP 8.0 release notes list it as a breaking change: "You must set the namespace in the module-level build.gradle.kts file, rather than the manifest file." Older plugins still keep their package name in the package attribute of AndroidManifest.xml, so the build stops as soon as your project moves to AGP 8. The error message includes the path of the module that needs fixing, and that path tells you which of the fixes below applies. This guide was checked against the Android developer docs, the AGP 8.0 release notes and the Flutter issue tracker on 2026-11-29.
The Namespace Fix: 4 steps
Short answer: read the module path in the error, upgrade that plugin, add the namespace yourself only if the module is your own, and patch an abandoned plugin only as a stopgap.
- Read the module path. The error names a project, such as
A problem occurred configuring project ':some_plugin', and a build file path. A path inside your.pub-cachefolder means a plugin. A path ending inandroid/app/build.gradlemeans your own app module. - Upgrade the plugin. Run
flutter pub outdatedto see newer versions, thenflutter pub upgrade --major-versions,flutter cleanandflutter pub get. Read the plugin's changelog first, because a major version can change its API. - Add the namespace to your own module. If the error points at
android/app, addnamespaceinside theandroid { }block, normally with the same value as yourapplicationId. - Stopgap for an abandoned plugin. If no fixed version exists, fork the plugin and add the namespace, or set it from your root
android/build.gradleas shown below. Then plan a replacement.
Why did this start after an upgrade?
Short answer: AGP 7.3 introduced the namespace property and AGP 8.0 made it mandatory, so any plugin that skipped it breaks the moment your project uses AGP 8.
The namespace is the Kotlin or Java package used for a module's generated R class, which is how code reaches its resources. Android's module configuration guide says the namespace is defined "by the namespace property in your module's build.gradle.kts file". Before AGP 8, a library could still provide it through the package attribute in its manifest. A Flutter plugin's Android code is a Gradle library module like any other, so the rule applies to every plugin in your pubspec.yaml, not only to your app.
Flutter's own tracker confirmed this early. In Flutter issue 125181, a Flutter team member summed it up: "AGP 8.0 requires the entire plugin ecosystem to add namespace to their build.gradle files." The same thread notes that apps using integration_test needed Flutter 3.10 to build with AGP 8. Toolchain upgrades, like the Gradle and SDK bumps in our Android 16 (API 36) upgrade guide for Google Play, are the usual moment this error appears.
Which module does the error point to?
Short answer: the file path in the message decides the fix, so copy it before you change anything.
| Path in the error | What it is | Fix |
|---|---|---|
.../.pub-cache/hosted/pub.dev/<plugin>-<version>/android/build.gradle | A plugin from pub.dev | Upgrade it; if it's abandoned, replace or fork it |
.../.pub-cache/git/<plugin>.../android/build.gradle | A plugin pulled from a Git repository | Add the namespace in that repository and update the ref |
android/app/build.gradle or .kts | Your own app module | Add namespace in the android { } block |
Don't edit the copy inside .pub-cache. It's a shared download cache, and your change disappears on the next clean fetch, including on CI.
How do you add the namespace to your own app module?
Short answer: add one line inside the android { } block of android/app/build.gradle, using the same value as your application ID.
// android/app/build.gradle.kts
android {
namespace = "com.example.myapp"
defaultConfig {
applicationId = "com.example.myapp"
}
}
// android/app/build.gradle (Groovy)
android {
namespace "com.example.myapp"
}
Android's guide recommends keeping the namespace "the same as your application ID, as they are by default". The two are separate settings, though. The application ID is the identity Google Play uses for your app. The namespace only names the generated R class. The guide also warns that if you don't set applicationId explicitly, it takes the namespace's value, so changing the namespace would change your app's identity. Keep applicationId set and unchanged. After the edit, remove the package="..." attribute from android/app/src/main/AndroidManifest.xml if it's still there, then run a full flutter build appbundle.
What if the plugin is abandoned?
Short answer: replace it with a maintained package if one exists; otherwise fork it, or use a root-level Gradle patch as a temporary bridge.
A fork is the cleanest stopgap. Add the namespace in the fork's android/build.gradle and remove the manifest package attribute. Then point your app at the fork with a git dependency, or with dependency_overrides, both described in Dart's package dependencies documentation.
The widely shared alternative sets a namespace for every library module that lacks one from your root android/build.gradle:
// android/build.gradle (Groovy), placed ABOVE the
// subprojects { project.evaluationDependsOn(":app") } block
subprojects {
afterEvaluate { project ->
if (project.hasProperty("android") && project.android.namespace == null) {
project.android.namespace = project.group
}
}
}
Placement matters. Gradle's API documentation for afterEvaluate says: "If the project has already been evaluated, this method fails." Below the evaluationDependsOn(":app") block, some modules are already evaluated, so the patch errors out instead of helping. Treat it as temporary, because it hides which plugins still need an update and the guessed namespace may not match the plugin's real package. Remove it once every plugin ships its own namespace.
How do you check the fix held?
Short answer: run a release build from a clean state, then test the release build on a device before you upload it.
- Run
flutter clean,flutter pub getandflutter build appbundle. A debug run alone can hide release-only problems; our list of reasons a Flutter app works in debug but not in release covers the usual ones. - If the build now stops at the manifest merger instead, a plugin may also need a higher minimum Android version; see how to fix "minSdkVersion cannot be smaller than version declared in library".
- Before uploading to Google Play, walk through our Flutter and Firebase release checklist.
We build and ship Flutter apps on Google Play at GSPTeck, giosaia's indie studio building mobile and web apps with Flutter and Firebase, and plugin upgrades like this one are part of every toolchain bump.
FAQ
Should the namespace match my applicationId?
Usually yes. Android's guide recommends keeping them the same, but they're separate settings. Keep applicationId set explicitly so a namespace change never changes your app's identity on Google Play.
Can I fix this by downgrading AGP?
It removes the error but keeps your project on an old toolchain, and the error returns at the next upgrade. Upgrading or replacing the plugin is the lasting fix.
Why shouldn't I edit the plugin inside .pub-cache?
The pub cache is a shared download folder. Your edit isn't part of your project, so a fresh fetch, another machine or a CI run brings the error back.
Does the root build.gradle patch work with Kotlin DSL files?
The same idea works in build.gradle.kts, but the syntax differs. Keep it above the evaluationDependsOn block in either language, and remove it once the plugins are updated.
Sources
- Android Gradle Plugin 8.0.0 release notes: namespace required in module-level build script (checked 2026-11-29)
- Android Developers: configure the app module, set the namespace (checked 2026-11-29)
- Flutter issue 125181: native plugins failing with AGP 8.0 (checked 2026-11-29)
- Gradle API: Project.afterEvaluate (checked 2026-11-29)
- Dart: package dependencies, git dependencies and dependency_overrides (checked 2026-11-29)