Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A problem occurred configuring project ':qr_code_scanner'. > 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: C:\Users\Tyro\AppD #751

Open
khaledmorshed opened this issue Oct 30, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@khaledmorshed
Copy link

Describe the bug
A clear and concise description of what the bug is.

Flutter information
Always provide the output of flutter doctor -v as it is needed in order to know on which Flutter versions the bug exists in.

Device (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@khaledmorshed khaledmorshed added the bug Something isn't working label Oct 30, 2024
@ne3Vubeki
Copy link

The same

@E2dwhy
Copy link

E2dwhy commented Nov 10, 2024

I am getting the same error... any updates on the fix pleasE?
here is the error I get after running flutter run

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':qr_code_scanner'.
> 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.
==============================================================================

I use
qr_code_scanner: ^1.0.1

and I can't find this file /build/qr_code_scanner/android/build.gradle
can anyone help me figure it out?

@MostafaEsmail007
Copy link

MostafaEsmail007 commented Nov 11, 2024

@E2dwhy

add in app/bulid.gradle

android {
        compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        coreLibraryDesugaringEnabled true
    }
}

dependencies {
    implementation 'androidx.window:window:1.3.0'
    implementation 'androidx.window:window-java:1.3.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'
}

and in gradle.properties

kotlin.jvm.target.validation.mode = IGNORE

@mehransahandi
Copy link

I also have a problem, after updating to gradle 8.x, the above suggestion does not work

@biel-correa
Copy link

had the same, I think something changed in a lower level because I had similar errors with other packages

@khaledmorshed
Copy link
Author

Bellow snippet code addding in android/build.gradle works for me.

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

afterEvaluate {
    if (it.hasProperty('android')) {
        // Check whether the android.namespace property is set.
        // If not, read the package name from the app's manifest file and set it as the namespace.
        if (it.android.namespace == null) {
            def manifest = new XmlSlurper().parse(file(it.android.sourceSets.main.manifest.srcFile))
            def packageName = [email protected]()
            println("Setting ${packageName} as android namespace")
            android.namespace = packageName
        }

        // Set both the sourceCompatibility and targetCompatibility to Java 17,
        // ensuring that both Java and Kotlin code are compiled with the correct target JVM version.
        def javaVersion = JavaVersion.VERSION_17
        android {
            def androidApiVersion = 34
            compileSdkVersion androidApiVersion
            defaultConfig {
                targetSdkVersion androidApiVersion
            }
            compileOptions {
                sourceCompatibility javaVersion
                targetCompatibility javaVersion
            }
        }

        // Ensure that all subprojects in the build follow the same Java version
        // and build directory configurations. Evaluate settings after all configurations
        // have been applied to make sure everything is in sync.
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            kotlinOptions {
                jvmTarget = javaVersion.toString()
            }
        }
    }
}

}

@mehransahandi
Copy link

thanks for the answer,but this is not the solution, I am wondering if there will be any update on package ?

@sTiagoLima
Copy link

same problem

@mehransahandi
Copy link

It seems this will not be updated anytime soon, so I switched to mobile_scanner from the same developer.

@E2dwhy
Copy link

E2dwhy commented Nov 20, 2024

I switched to mobile_scanner Works fine so far thanks guys @ALL

@may-tas
Copy link

may-tas commented Dec 9, 2024

it is because the namespace property is not specified, you will have to go to in mac :
/Users/(your_username)/.pub-cache/hosted/pub.dev/qr_code_scanner (version as u use)/ android/ build.gradle.

And in the build.gradle file you will see :

  • group ' some package name (this is the namespace) ' .
  • Just copy the group value and go to android block and write :
  • namespace " group value i.e namespace value".
  • Done , Save the file and re-run , it will work now.
  • If you encounter the same problem in any other package, do the same thing.

Eg. I have attached a screenshot for a package build.gradle file :
Screenshot 2024-12-09 at 11 54 06 PM

@AhmedAlboishe
Copy link

AhmedAlboishe commented Dec 13, 2024

Add this code in build.gardle:

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

image

@sueputhearathblue
Copy link

it not work all i try as above

@fatima-tehreem09
Copy link

I got the same error while running my app on Flutter's latest version. There is a replacement of this plugin called qr_code_scanner_plus: ^2.0.7.
I have resolved this issue by replacing the old plugin with a new one.

@mvharikrishnan
Copy link

I have also encountered the same issue while using this package! since this package haven't updated from last 2 years i have moved to a new one called mobile scanner!

@Vladimir4063
Copy link

Tenia el mismo problema y se soluciono.
El paquete era: flutter_barcode_scanner.

pero a mi entender, no es un problema del paquete, sino de la versión de Gradle.

Mi problema se soluciono al agregar este código en build.gradle de android, no de app.

`allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = "../build"

#Codigo Agregado. ##########
subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }
}
#fin del código agregado ##########

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests