Flutter踩坑记-第三方SDK不兼容Gradle 8.0,需适配namespace
最近需要集成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 = 35
defaultConfig {
minSdk = 21
targetSdk = 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
}
}
}
}
}
感谢大家的支持,如有错误请指正,如需转载请标明原文出处!