3

Suddenly I'm getting the namespace error in my flutter project.

  • What went wrong: A problem occurred evaluating root project 'android'.

A problem occurred configuring project ':app'. Could not create an instance of type com.android.build.api.variant.impl.ApplicationVariantImpl. > 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.
enter code here

enter image description here

Thank you in advance for the help.

5

5 Answers 5

1

Read what the error tells you.

In newer versions of AGP, the declaration of namespace/package was moved from AndroidManifest and to build script.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    <!-- package="com.example.app" POOF! -->
>

and

android {
    namespace = "com.example.app"
Sign up to request clarification or add additional context in comments.

4 Comments

I already did that, but still it shows that error
@Yogendra same with me, any updates ?
@AhmedElhenidy yeah, for me I couldn't upgrade my packages, and this error is being thrown for packages which are old, so I had to downgrade the AGP/Gradle version to v5.4.1
the main idea is that I have to upgrade my gradle version. any way, thanks
1

This worked for me. Include this in your project level build.gradle file:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace = project.group.toString()  // Set namespace as fallback
                }
                project.tasks.whenTaskAdded { task ->
                    if (task.name.contains('processDebugManifest') || task.name.contains('processReleaseManifest')) {
                        task.doFirst {
                            File manifestFile = file("${projectDir}/src/main/AndroidManifest.xml")
                            if (manifestFile.exists()) {
                                String manifestContent = manifestFile.text
                                if (manifestContent.contains('package=')) {
                                    manifestContent = manifestContent.replaceAll(/package="[^"]*"/, "")
                                    manifestFile.write(manifestContent)
                                    println "Removed 'package' attribute from ${manifestFile}"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Source on medium

Comments

0
compileOptions
{
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions
{
    jvmTarget = '17'
}

Upgrade the Java version to 17 in the app-level build.gradle file. This adjustment should resolve the issue in my scenario.[1]: https://i.sstatic.net/8zRn6.png

Comments

0

I encountered the same error you described while using the flutter_login_facebook package version 2.0.1. The error you're seeing is likely related to namespace conflicts.

To resolve this, I added the following namespace declaration:

android {
    namespace "ru.innim.flutter_login_facebook"
}

This was added to the build.gradle file of the flutter_login_facebook module. In my case, the file was located at:

/Users/mac/.pub-cache/hosted/pub.dev/flutter_login_facebook-2.0.1/android/build.gradle

After modifying the build.gradle file, I performed the following steps:

  1. Remove or comment out the package name from pubspec.yaml: This is to ensure a clean slate.

  2. Run flutter clean: This clears the build artifacts.

  3. Add the package name back to pubspec.yaml and Run flutter pub get: This re-installs the package with the namespace fix.

  4. Run the Flutter project again: This rebuilds the app with the changes.

This process resolved the error for me without requiring an upgrade of the flutter_login_facebook package (as there was no update) or reverting to an older Flutter version.

I hope this solution is helpful.

1 Comment

Faced the same issue with flutter_wallpaper_manager:0.0.4 recently (pub.dev/packages/flutter_wallpaper_manager).
0

Just add the namespace in build.gradle file
app/build.gralde

android {
    namespace "com.android.example"
}

Note: Namespace get from main/kotlin/MainActivity Check package com.android.example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.