| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- allprojects {
- repositories {
- google()
- mavenCentral()
- }
- }
- rootProject.buildDir = '../build'
- subprojects {
- project.buildDir = "${rootProject.buildDir}/${project.name}"
- // AGP 8 强制要求每个模块声明 namespace,但老式插件(如 alipay_kit_android 6.0.0)
- // 未声明。这里在插件内部 afterEvaluate 创建 variant 之前,从 AndroidManifest 的
- // package 属性自动补 namespace(AGP 8 标准 workaround)。
- // 注意:必须放在 evaluationDependsOn(':app') 之前注册——否则子工程被提前求值,
- // afterEvaluate 会抛 "project is already evaluated"。
- afterEvaluate { proj ->
- def isAndroid = proj.plugins.hasPlugin('com.android.library') ||
- proj.plugins.hasPlugin('com.android.application')
- if (!isAndroid) return
- def androidExt = proj.extensions.findByName('android')
- if (androidExt == null) return
- // namespace 已显式声明时无需处理
- if (androidExt.hasProperty('namespace') &&
- androidExt.namespace != null && !androidExt.namespace.isEmpty()) return
- def manifestFile = proj.file('src/main/AndroidManifest.xml')
- if (!manifestFile.exists()) return
- try {
- def manifest = new XmlSlurper().parse(manifestFile)
- def pkg = manifest.@package.text()
- if (pkg) {
- androidExt.namespace = pkg
- println "Auto namespace for ${proj.name}: ${pkg}"
- }
- } catch (Exception ignore) {
- // manifest 解析失败时保持默认,让 AGP 继续报错提示
- }
- }
- }
- subprojects {
- project.evaluationDependsOn(':app')
- }
- tasks.register("clean", Delete) {
- delete rootProject.buildDir
- }
|