flutter_install_plugin icon indicating copy to clipboard operation
flutter_install_plugin copied to clipboard

Build failed in flutter 3.24

Open Mahdi-Panahi opened this issue 1 year ago • 9 comments

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':install_plugin:verifyReleaseResources'.

A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action Android resource linking failed ERROR:C:***\install_plugin\intermediates\merged_res\release\values\values.xml:211: AAPT: error: resource android:attr/lStar not found.

Mahdi-Panahi avatar Sep 07 '24 12:09 Mahdi-Panahi

Same error occurred on flutter 3.24. Please fix

brandonLYQ00 avatar Sep 13 '24 03:09 brandonLYQ00

I get a different error with 3.24. To keep it clean, I created a brand new, empty (default example app) flutter project, and then just added install_plugin to the pubspec. This results in the following build error:

FAILURE: Build failed with an exception.

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

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.

brandyn avatar Sep 14 '24 17:09 brandyn

The issue is related to namespace, to fix this they need to release PR #67

camillobucciarelli avatar Sep 23 '24 16:09 camillobucciarelli

Workaround

android/app/build.gradle

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

android/build.gradle

// .....
rootProject.buildDir = '../build'

// FIX for Flutter 3.24
subprojects {
    afterEvaluate {
        android {
            compileSdkVersion 34
        }
    }
}

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')
}

//.....

gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
kotlin.jvm.target.validation.mode = IGNORE

gradle-wrapper.properties

distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

settings.gradle

   id "com.android.application" version "8.3.2" apply false
   id "org.jetbrains.kotlin.android" version "2.0.20" apply false

khaled-0 avatar Oct 29 '24 15:10 khaled-0

Workaround android/build.gradle

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

rootProject.buildDir = '../build'

// FIX for Flutter 3.24
subprojects {
    afterEvaluate {
        android {
            compileSdkVersion 34
        }
    }
}

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')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

After that, the following error occurs:

Execution failed for task ':install_plugin:compileDebugKotlin'.

'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version. Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

reynegton avatar Nov 01 '24 11:11 reynegton

Workaround android/build.gradle

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

rootProject.buildDir = '../build'

// FIX for Flutter 3.24
subprojects {
    afterEvaluate {
        android {
            compileSdkVersion 34
        }
    }
}

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')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

After that, the following error occurs:

Execution failed for task ':install_plugin:compileDebugKotlin'.

'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version. Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

updated my comment to include full changes i did

khaled-0 avatar Nov 01 '24 12:11 khaled-0

this build.gradle worked for me

group 'com.example.installplugin'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

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

    kotlinOptions {
        jvmTarget = '17'
    }
    compileSdkVersion 30
    namespace = "com.example.installplugin"
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    defaultConfig {
        minSdkVersion 16
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
}

dara1chan avatar Dec 07 '24 04:12 dara1chan

install_plugin kotlinOptions.jvmTarget not set, use default jdk. log: install_plugin sourceSet: 1.8, kotlinJvm: 17

this /android/build.gradle.kts worked for me

subprojects {
    afterEvaluate {
        // 仅处理应用了 Android 插件的模块
        pluginManager.withPlugin("com.android.application") {
            configureAndroidModule()
        }
        pluginManager.withPlugin("com.android.library") {
            configureAndroidModule()
        }
    }
}

fun Project.configureAndroidModule() {
    val android = extensions.findByType<com.android.build.gradle.BaseExtension>()

    // 配置 Kotlin 编译任务
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
        val sourceSet = android?.compileOptions?.sourceCompatibility?.toString() ?: "17"
        val kotlinJvm = kotlinOptions.jvmTarget?.toString() ?: ""
        println("${project.name} sourceSet: $sourceSet, kotlinJvm: $kotlinJvm")
        if(kotlinJvm != sourceSet) {
            kotlinOptions.jvmTarget = sourceSet
        }
    }
}

JimChenCn avatar Apr 03 '25 06:04 JimChenCn

I get a different error with 3.24. To keep it clean, I created a brand new, empty (default example app) flutter project, and then just added install_plugin to the pubspec. This results in the following build error:

FAILURE: Build failed with an exception.

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

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.

请问这个有解决吗

xuelangjie avatar May 29 '25 10:05 xuelangjie