allprojects {
    repositories {
        flatDir {
            dirs 'libs'
        }

        google()
        mavenCentral()
    }
}

subprojects {
    afterEvaluate { project ->
//        if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) {
//            println "project: ${project.name} Namespace get: ${project.android.namespace}"
//            def packageName = project.android.namespace ?: project.android.defaultConfig.applicationId ?: project.android.sourceSets.main.manifest.srcFile.text.find(/package="([^"]*)"/) ?: project.group
////            project.android.namespace = packageName
////            println "Namespace set to: ${packageName} for project: ${project.name}"
//
//            // 如果包名不包含 "com.baidu"，则设置命名空间
//            if (packageName.contains('com.baidu')) {
//                println "Skipping namespace setting for project ${project.name} as the package name contains 'com.baidu' or 'isar_flutter_libs'"
//            } else {
//                project.android.namespace = packageName
//                println "Namespace set to: ${packageName} for project: ${project.name}"
//            }
//        }
        if (project.plugins.hasPlugin("com.android.application") ||
                project.plugins.hasPlugin("com.android.library")) {
            project.android {
                compileSdkVersion 34
                buildToolsVersion "34.0.0"
            }
        }
        if (project.hasProperty("android")) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }

    // ============
    project.buildDir = "${rootProject.buildDir}/${project.name}"
//    project.evaluationDependsOn(":app")
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
//}
//subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}
