skip to Main Content

I am trying to work on my Flutter app, and I have migrated to the declarative apply of Flutter’s plugins. However, this has now created another issue that I have no clue how to fix.

Launching libmain.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':android_intent'.
> 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.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
Error: Gradle task assembleDebug failed with exit code 1

The error is shown above, and I can’t figure out why I am getting an error. I have defined a namespace in the app/build.gradle file also, and I am completely lost. Any help would be very appreciated!

android {
    namespace "com.example.cyclesync"
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

2

Answers


  1. I suggest deleting the android folder from you project and then running the following command in the terminal at your project’s root directory:

    flutter create .
    

    This command will recreate your android folder clean and hopefully resolve the namespace issue.

    Login or Signup to reply.
  2. For me this error was happening when importing the package webview_cookie_manager but I’ve had it happen on others too. For you it seems to triggering specificly on the package android_intent.

    To fix this, in your android/build.gradle (NOT android/app/build.gradle), add this gradle script:

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

    So the whole file should look somewhat like:

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = "../build"
    subprojects {
        afterEvaluate { project ->
            if (project.hasProperty('android')) {
                project.android {
                    if (namespace == null) {
                        namespace project.group
                    }
                }
            }
        }
    }
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(":app")
    }
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    

    So if the dependency doesn’t already have a specified namespace, the code will automatically assign one using the package name.
    Hope this helps! Let me know if you have any questions 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search