I am working on fixing an old app for a client that an agency wrote for him. After fixing a few issues and upgrading dependencies, I got stuck in the build process. The main issue is that the namespace of modules that should be dependencies is not specified.
A problem occurred configuring project ':notification_permissions'.
> 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. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
>
I consulted ChatGPT extensively and it suggested to turn the dependency into a module and providing the namespace there. For accessing its build file it suggested to clone the repository and change the gradle file to include the namespace. As I couldn’t imagine that it would make sense to clone repositories of dependencies to manage them myself just to fix a namespace error, I asked for alternatives, and it suggested to fork the repo remotely and maintain it there. I can’t imagine that the best practice is for everyone using the repository to basically fork and maintain it just to manage a namespace issue.
Relevant answers I found (see below) suggested that the issue was with AGP for old gradle versions. However, this is not available in the market place (or doing it automatically) in either Android Studio and IntelliJ. And if I’m on the latest gradle it shouldn’t be an issue, should it? ChatGPT suggests to upgrade manually, which I did, but this doesn’t change anything.
I wonder if I missed something important or my toolchain is messed up.
I am sorry if this sort of question is incorrectly put here as it is more a discussion on best practice instead of a set code / toolchain issue.
These are the respective gradle files if your answer is on a code-level (I am aware that I should switch to declarative style, but I don’t want to conflate issues) with the name of the project replaced by ***; I also appreciate discussion on what is the best overall approach here, as ChatGPTs suggestions seem curious to say the least…
androidappbuild.gradle
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace '***'
compileSdkVersion 34
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "***"
minSdkVersion flutter.minSdkVersion
targetSdkVersion 34
multiDexEnabled true
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
compileOptions
{
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions
{
jvmTarget = '17'
}
}
flutter {
source '../..'
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics'
}
androidbuild.gradle
buildscript {
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.15'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
androidgradlewrappergradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Things I tried:
- This post (How do I fix ‘namespace not specified’ error in Android Studio?) suggested to upgrade AGP. It doesn’t automatically ask for updating when I specify gradle to an old version (
distributionUrl=https://services.gradle.org/distributions/gradle-7.4-2-bin.zip
in gradle-wrapper) and it does not appear in the market place either in intellij or Android Studio and I don’t even get to the run step.
- This post (Namespace not specified. Specify a namespace in the module’s build file Flutter Android Studio) also refers to AGP and moving the namespace to the build script, which I already did. Adding the compile and kotlin options
- This post (Namespace not specified. Please specify a namespace in the module’s build.gradle while building flutter application apk) suggests to move the module to the namespace. However, I don’t find the module in the manifest file
Other posts did not address the problem.
flutter doctor showed that all is good (except for VSCode which I don’t use) and I got the latest dependencies (flutter pub get and clean).
Simon Johanning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.