当我们想要动态的修改AndroidManifest.xml文件中一些熟悉时,可以通过manifestPlaceholders占位符来完成,首先在AndroidManifest.xml文件中预先设置一些占位符,例如
<meta-data
android:name="appkey"
android:value="${appKey}"/>
<meta-data
android:name="appId"
android:value="${appId}"/>
在build.gradle文件中就可以通过manifestPlaceholders来给这些变量赋值
android {
compileSdkVersion 31
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.android3"
minSdkVersion 28
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [
appId: "ALIHK16BE69B261920",
appKey: "ALIHK16BE69B261920_ANDROID"
]
}
}
如果我们想要在gradle文件中执行一些终端命令,比如 chmod加权限,copy之类的,举个例子,调用终端的echo打印一句话
echo hello world
可以直接在gradle文件中写
"echo hello world".execute()
如果想要看到这个命令的执行结果,可以用println把它打印出来
println "echo hello world".execute().trim()
```