[BUG] After updating to Flutter 3.24.3, an error occurred.
Opened this issue · 16 comments
Describe the bug
I updated Flutter to version 3.24.3, and encountered the following error.
- 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.
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.
flutter --version
Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2663184aa7 (4 days ago) • 2024-09-11 16:27:48 -0500
Engine • revision 36335019a8
Tools • Dart 3.5.3 • DevTools 2.37.3
Device (please complete the following information):
- Device: [phone api 35 ]
- OS: [e.g. iOS8.1]
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
+1
+1
+1
+1
the same here.. any workaround?
+1
Same
+1
+1
qr_code_scanner:
git:
url: https://github.com/asmrtfm/qr_code_scanner
ref: patch-1
version: ^1.0.0
Thanks @vshvedov works!
Thanks @vshvedov works fine
instead of forking each repo that's causing the problem after adding the namespace, add this in your project's build.gradle in a spearate subprojects block:
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 = 35
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()
}
}
}
}
}
this will add the namespace to the gradles automatically while the app is being built
Same issue
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
add this block inside your module level build.gradle file
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