a284628487 / AndroidPoint

Android Note
1 stars 0 forks source link

Android Processor #16

Open a284628487 opened 3 years ago

a284628487 commented 3 years ago

修改AndroidManifest.xml

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.processResources.doFirst { pm ->
            String manifestPath = output.processResources.manifestFile
            println "=====ManifestPath=====$manifestPath"
            // N:\xx\build\intermediates\merged_manifests\debug\AndroidManifest.xml
            def manifestContent = file(manifestPath).getText()
            def xml = new XmlParser().parseText(manifestContent)
            xml.application[0].appendNode("meta-data", ['android:name': 'channel', 'android:value': 'baidu'])
            def serialize = groovy.xml.XmlUtil.serialize(xml)
            file(manifestPath).write(serialize)
        }

        println "originalFileName: ${outputFileName}"
        outputFileName = "xxxxx.apk"
    }
}
a284628487 commented 2 years ago
    project.android.applicationVariants.all { variant -> variant.outputs.all {
            println("variant: ${variant}")
            outputFileName = "${variant.name}-${variant.versionName}.apk"
        }
    }

    Object androidComponents = project.extensions.getByType(AndroidComponentsExtension.class)
    println("components: ${androidComponents}") // extension 'androidComponents'
a284628487 commented 2 years ago

获取其它应用资源文件

val pkgContext = createPackageContext("com.example.myapp2", 0)
Log.e("TAGGG", "pkgName: ${pkgContext.packageName}")

val res = packageManager.getResourcesForApplication("com.example.myapp2")
val ins = res.assets.open("loading.json")
a284628487 commented 2 years ago

代码检测:

coverity
findbugs
lint
checkstyle
detekt