Namespace not specified for AGP 8.0.0

Hi! Need some help with Android Gradle Plugin update. When I try to update project from 7.4.2 to 8.0.0 I get an error:

Namespace not specified. Please specify a namespace in the module's build.gradle file like so:

android {
    namespace 'com.example.namespace'

If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to for more information.

Namespaces have been set already with 7.4.2 and everything works as expected - what should I do to get rid of this error?
I see on Google that there is / was some sort of bug with this, but didn’t find any suggestions on what should be done.

did u update it with the AGP Upgrade Assistant? let me know please.

Yes, but issue seems to be caused by libraries I am using. They are not up to date with Gradle requirement for namespaces.

normally,it will add namespace automictically in the dependent mocule’s build.gradle file when u update AGP with AGP Upgrade Assistant. u can remove the “package” attribute in the AndroidManifest.xml file, and add the namespace line under android{} in buile.gradle file, if AGP Upgrade Assistant failed.

You can resolve the namespace issue after updating to AGP 8.+ by adding the following script in the android/build.gradle file:

subprojects {
   afterEvaluate { project ->
       if (project.hasProperty('android')) {
               if (namespace == null) {

Thanks, worked for me. Changed upgrade build to 8.2.2 first which didn’t help but adding subprojects {} did the trick.

1 Like

But be aware that this is a big pile of stacked bad practices.
subprojects { ... } => bad practice
afterEvaluate { ... } => bad practice
project.hasProperty how it is used here => bad practice

Better just define your namespaces in your build scripts,
or if you want it centralized, use a convention plugin.

This was for two AS projects built under 7.2 which when reopened after 15 months and following an auto update to 8.2.0 gave the namespace error. I spent a couple of hours trying to apply the documented fixes to no avail. Found this solution and it worked, so bad practice or not, it saved a lot of frustration, I have since removed the script from the gradle_build. I haven’t wasted that much time on Gradle errors since 2015 when they were very common.

Well, that snippet is not doing more than if you would just set the namespace with

android {

in each Android project in the build where you did not have set a namespace yet, just in a bad way.

Do whatever works for you, just wanted you to know it is stacked bad practices and bad practices are so for a reason usually. :wink:

In my case, it was a Flutter project with a substantial list of third-party packages needing namespace updates. Even if I were to create PR with namespace declaration for each, I’d still have to wait for the package owners to release a new version :sweat_smile:

Aren’t those Flutter dependencies included builds as far as I remember?
Those would not be affected by your snippet anyway.

I’m not entirely sure I grasp what you’re suggesting, but in practice, after migrating, the main project’s Gradle sync throws an error, directing me to update the namespaces in the dependencies. Adding the namespace directly in the Flutter cache works that only lasts until the next project sync. Hence, I had to implement this workaround and it works for me.

I don’t disagree, the 8.2.0 build did not recognise that though. These were two projects that had been built and deployed successfully in the past. The update from 7.4 failed with the no namespace error. I tried manually removing the original namespace and typing it in again etc. Anyhow, all good since manually changing build to 8.2.2 and synching again. Perhaps the issue was with 8.2.0.

1 Like