flutter_credit_card icon indicating copy to clipboard operation
flutter_credit_card copied to clipboard

Project build Android Gradle lacking the namespace

Open davemg3 opened this issue 1 year ago • 4 comments

A problem occurred configuring project ':flutter_credit_card'.
      > 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.

This error occurs after Android Gradle Plugin updated >= 8.x.x. To get rid of error use following method:

In your build.gradle you can conditionally set the namespace using the following:

android {
     ...
     if (project.android.hasProperty("namespace")) {
         namespace("change.this.to.your.namespace")
     }

davemg3 avatar Jan 26 '24 00:01 davemg3

Having same issue, the namespace is already set in build.gradle but getting this error after adding flutter_credit_card widget.

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring project ':flutter_credit_card'.

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 1s Error: Gradle task assembleDebug failed with exit code 1

navaidali avatar Mar 08 '24 12:03 navaidali

A problem occurred configuring project ':flutter_credit_card'.
      > 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.

This error occurs after Android Gradle Plugin updated >= 8.x.x. To get rid of error use following method:

In your build.gradle you can conditionally set the namespace using the following:

android {
     ...
     if (project.android.hasProperty("namespace")) {
         namespace("change.this.to.your.namespace")
     }

This solution didn't work. I have integrated credit card in my project. The namespace of the project is already in the build.gradle, why should I add "flutter_credit_card" as a name space???

navaidali avatar Mar 08 '24 12:03 navaidali

As you said you added a namespace for your project but not for the library. If the libray dev has included the namespace in his package, you dont have too but if it is missing (which is the case here) you can set a namespace by writing following in android/buid.gradle :

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

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

subprojects {
    project.evaluationDependsOn(':app')
}

My first message was for the developper of the library so as he can update his package

davemg3 avatar Mar 10 '24 12:03 davemg3