最近需要集成Flutter作为Module,Flutter依赖了第三方库,Gradle是8.0版本。
编译报错:
解决办法是在.android根目录下的build.gradle下新增一行代码:
buildscript {ext.kotlin_version = "1.8.22"repositories {google()mavenCentral()}dependencies {classpath("com.android.tools.build:gradle:8.1.0")classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")}
}allprojects {repositories {google()mavenCentral()}
}subprojects {afterEvaluate { project ->if (project.hasProperty('android')) {project.android {if (namespace == null) {namespace project.group}}}}
}apply plugin: "com.android.library"
apply plugin: "kotlin-android"android {// Conditional for compatibility with AGP <4.2.if (project.android.hasProperty("namespace")) {namespace = "com.virbo.virbo_flutter"}compileSdk = 35defaultConfig {minSdk = 21targetSdk = 35}
}dependencies {implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version")
}
核心代码是:
subprojects {afterEvaluate { project ->if (project.hasProperty('android')) {project.android {if (namespace == null) {namespace project.group}}}}
}
感谢大家的支持,如有错误请指正,如需转载请标明原文出处!