Debugging log · Gradle
"Namespace not specified" after an AGP upgrade
I bumped the Android Gradle Plugin on an older project, synced, and the build stopped with a flat demand for a namespace — something I'd never had to set before. The project had built for years without it. What changed is that newer AGP made explicit a value that used to be inferred quietly from the manifest, and now it wants you to state it.
The short version: AGP 8+ requires each module to declare a namespace in its build.gradle. It used to be taken from the package attribute in AndroidManifest.xml; now you set it in Gradle and remove it from the manifest. Android Studio can migrate it for you in one click.
The error
Namespace not specified. Specify a namespace in the module's build file. See https://... for information about setting the namespace.
What the namespace is
The namespace is the package name used for your module's generated R class and BuildConfig — the internal identity of your code. Historically this came from the package attribute at the top of AndroidManifest.xml, and AGP inferred everything from there. Newer AGP separates two ideas that were tangled together: the namespace (where your R/BuildConfig live) and the applicationId (your app's identity on the device and Play). Pulling the namespace into Gradle makes that split explicit.
The fix — set it in build.gradle
Add a namespace to the android { } block of the module:
android {
namespace = "com.example.myapp"
compileSdk = 34
// ...
}
Use the value that was in your manifest's package attribute, so your existing R references keep resolving. Then remove the package attribute from AndroidManifest.xml — leaving it there alongside the Gradle namespace causes its own warnings/errors:
<!-- before --> <manifest xmlns:android="..." package="com.example.myapp"> <!-- after --> <manifest xmlns:android="...">
Let Android Studio do it
You usually don't have to edit by hand. Android Studio offers a migration: Refactor → Migrate to Namespace (or the quick-fix in the sync error) moves the package to the Gradle namespace and cleans the manifest across your modules. On a multi-module project this is far safer than doing each by hand, because every module needs its own namespace and they must stay unique.
Gotchas on multi-module projects
- Every module needs one. Each library module requires its own
namespace, and two modules must not share the same value. - Namespace vs applicationId. Only the app module has an
applicationId; library modules have a namespace but no applicationId. Don't add one to a library. - Old libraries without a namespace. A very old dependency that still relies on a manifest package can trip the same error indirectly — update it if so.
- Keep the namespace stable. Changing it moves your
R/BuildConfigpackage, which breaks imports across your code. Match the old package exactly unless you intend a wider refactor.
Namespace and applicationId can be the same string, and often are — but they're now independent settings. If you ever want to ship under a different applicationId than your code's package, this separation is what makes it clean rather than a hack.
The package name above is an example — use your project's own.