allprojects { repositories { google() mavenCentral() } } val newBuildDir: Directory = rootProject.layout.buildDirectory .dir("../../build") .get() rootProject.layout.buildDirectory.value(newBuildDir) subprojects { val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) project.layout.buildDirectory.value(newSubprojectBuildDir) } gradle.beforeProject { val flutterExt = extensions.findByName("flutter") if (flutterExt != null) { try { var klass: Class<*>? = flutterExt.javaClass var field: java.lang.reflect.Field? = null while (klass != null && field == null) { try { field = klass.getDeclaredField("ndkVersion") } catch (e: NoSuchFieldException) { klass = klass.superclass } } if (field != null) { field.isAccessible = true field.set(flutterExt, "30.0.16248370") } } catch (e: Exception) { logger.warn("无法反射修改 flutter.ndkVersion: ${e.message}") } } plugins.withId("com.android.application") { extensions.findByType()?.apply { buildToolsVersion = "37.0.0" externalNativeBuild { cmake { version = "4.1.2" } } } } plugins.withId("com.android.library") { extensions.findByType()?.apply { buildToolsVersion = "37.0.0" externalNativeBuild { cmake { version = "4.1.2" } } } } afterEvaluate { val libExt = extensions.findByType() if (libExt != null) { libExt.compileSdk = 37 libExt.compileSdkMinor = 2 } } } subprojects { project.evaluationDependsOn(":app") } tasks.register("clean") { delete(rootProject.layout.buildDirectory) } // 强制所有子项目(含插件模块)使用 Java 17,消除 "源值 8/目标值 8 已过时" 警告 gradle.beforeProject { if (project != rootProject) { tasks.withType(JavaCompile::class.java).configureEach { sourceCompatibility = JavaVersion.VERSION_17.toString() targetCompatibility = JavaVersion.VERSION_17.toString() } plugins.withId("com.android.library") { extensions.findByType(com.android.build.api.dsl.LibraryExtension::class.java)?.apply { compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } } } } }