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 https://developer.android.com/studio/build/agp-upgrade-assistant 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.
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.
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.
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
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.