juliuscanute / qr_code_scanner

QR Code Scanner for Flutter
BSD 2-Clause "Simplified" License
1.01k stars 793 forks source link

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 2 weeks ago

khaledmorshed commented 2 weeks ago

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):

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

Additional context Add any other context about the problem here.

ne3Vubeki commented 2 weeks ago

The same

E2dwhy commented 4 days ago

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 commented 3 days ago

@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 commented 2 days ago

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

biel-correa commented 2 days ago

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

khaledmorshed commented 1 day ago

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 = manifest.@package.text()
            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()
            }
        }
    }
}

}