Flutter踩坑记-第三方SDK不兼容Gradle 8.0,需适配namespace

最近需要集成Flutter作为Module,Flutter依赖了第三方库,Gradle是8.0版本。

编译报错:


解决办法是在.android根目录下的build.gradle下新增一行代码:

groovy 复制代码
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")
}

核心代码是:

groovy 复制代码
subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }
}

感谢大家的支持,如有错误请指正,如需转载请标明原文出处!

相关推荐
恋猫de小郭5 小时前
Android Keep Rules 解读,直接影响 Google Play 上架和曝光
android·前端·flutter
恋猫de小郭1 天前
Flutter A2UI 1.0 ,原来的 genui 也正式换成了这一套 SDK 了
android·前端·flutter
LinXunFeng1 天前
A2UI 1.0 详解:让 AI 生成 Flutter 界面,还不怕它乱写
前端·flutter·agent
好的佩奇2 天前
Dart 之元数据与注解
android·flutter·dart
恋猫de小郭4 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
好的佩奇5 天前
蓝牙之设备角色与连接
android·flutter·蓝牙
SoaringHeart6 天前
Flutter最佳实践:用 flutter_html 渲染富文本
前端·flutter
恋猫de小郭6 天前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
程序员老刘7 天前
跨平台开发地图 | 2026年11月
flutter·ai编程·客户端
传奇开心果编程7 天前
【Flutter踩坑排雷】第30课:异常未捕获坑|未捕获异常直接闪退,全局兜底故障处理
android·flutter·ios·移动开发·dart·ui框架·声明式ui