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

Compatible with AGP-8.0+ #596

Merged

Conversation

naivetoby
Copy link
Contributor

你好,我在升级到 Flutter 3.19.0 时,根据最新的文档

https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

升级了 gradle 版本为 gradle-8.2-bin.zip,相关的配置文件,片段如下

settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.2.2" apply false
    id "org.jetbrains.kotlin.android" version "1.9.22" apply false
}

include ":app"

build.gradle

...
android {
    namespace 'xxx.xxx.xxx'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            kotlinOptions.jvmTarget = "17"
        }
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}
...

结果 fluwx 无法编译成功,出现了两个问题:

  1. 没有强制指定 JDK 编译版本,会出现如下错误
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

# 添加如下配置后解决

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}
  1. 文件 com.jarvan.fluwx.handlers.WXAPiHandler 有一个貌似无效的引用会报错
import com.jarvan.fluwx.BuildConfig

去掉以后正常,暂时不知道是否有影响

@JarvanMo
Copy link
Member

感谢。我昨天忙忘了,晚上我看看。

@JarvanMo
Copy link
Member

I'll merge this PR but it seems like sourceCompatibility is incorrect.

@JarvanMo JarvanMo merged commit fcc668c into OpenFlutter:master Feb 19, 2024
2 of 3 checks passed
@JarvanMo
Copy link
Member

Released with 4.4.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants