build.gradle 配置详解1
//声明是Android程
apply plugin: 'com.android.application'
android {
//程序在编译的时候会检查lint,有任何错误提示会停止build,我们可以关闭这个开关
lintOptions {
abortOnError false
//即使报错也不会停止打包
checkReleaseBuilds false
//打包release版本的时候进行检测
}
compileSdkVersion 23
//编译sdk的版本,也就是API Level,例如API-19、API-20、API-21等等。
buildToolsVersion '23.0.2'
//build tools的版本,其中包括了打包工具aapt、dx等等。
//这个工具的目录位于你的sdk目录/build-tools/下
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
//关闭Android Studio的PNG合法性检查的
defaultConfig {
applicationId "com.xiaopao.activity"
//应用包名
minSdkVersion 15
//最小sdk版本,如果设备小于这个版本或者大于
//maxSdkVersion(一般不用)将无法安装这个应用
targetSdkVersion 22
//目标sdk版本,如果设备等于这个版本那么android平台
//就不进行兼容性检查,运行效率会高一点
versionCode 15
//版本更新了几次,第一版应用是1,以后每更新一次加1
versionName '1.411'
//版本信息,这个会显示给用户,就是用户看到的版本号
archivesBaseName = "weshare-$versionName"
//指定打包成Jar文件时候的文件名称
ndk {
moduleName "xiaopaowifisafe" //设置库(so)文件名称
ldLibs "log", "z", "m", "jnigraphics", "android"
//引入库,比如要用到的__android_log_print
abiFilters "armeabi", "x86", "armeabi-v7a" //, "x86" 显示指定支持的ABIs
cFlags "-std=c++11 -fexceptions" // C++11
stl "gnustl_static"
}
multiDexEnabled true
//当方法数超过65535(方法的索引使用的是一个short值,
//而short最大值是65535)的时候允许打包成多个dex文件,动态加载dex。这里面坑很深啊
}
//默认的一些文件路径的配置
sourceSets {
main {
assets.srcDirs = ['assets'] //资源文件
jni.srcDirs 'src/main/jni' //jni文件
jniLibs.srcDir 'src/main/jniLibs' //jni库
}
}
//multiDex的一些相关配置,这样配置可以让你的编译速度更快
dexOptions {
preDexLibraries = false
//让它不要对Lib做preDexing
incremental true
//开启incremental dexing,优化编译效率,这个功能android studio默认是关闭的。
javaMaxHeapSize "4g" //增加java堆内存大小
}
buildTypes {
release { //release版本的配置
zipAlignEnabled true //是否支持zip
shrinkResources true // 移除无用的resource文件
minifyEnabled true //是否进行混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//release的Proguard默认为Module下的proguard-rules.pro文件.
debuggable false //是否支持调试
//ndk的一些配置
ndk {
// cFlags "-std=c++11 -fexceptions -O3 -D__RELEASE__" // C++11
// platformVersion = "19"
moduleName "xiaopaowifisafe" //设置库(so)文件名称
ldLibs "log", "z", "m", "jnigraphics", "android"
//引入库,比如要用到的__android_log_print
abiFilters "armeabi", "x86", "armeabi-v7a"//, "x86"
cFlags "-std=c++11 -fexceptions" // C++11
stl "gnustl_static"
}
//采用动态替换字符串的方式生成不同的release.apk
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('release.apk')) {
def timeStamp = new Date().format('yyyyMMddHH');
def fileName = "WeShare-${defaultConfig.versionName}" + "-" + timeStamp + "-lj-" + ".apk";
output.outputFile = file("${outputFile.parent}/${fileName}")
}
}
}
jniDebuggable false //关闭jni调试
}
debug {//debug版本的配置
minifyEnabled false
zipAlignEnabled true
shrinkResources true // 移除无用的resource文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
// jniDebuggable true
ndk {
cFlags "-std=c++11 -fexceptions -g -D __DEBUG__" // C++11
}
jniDebuggable true
}
}
compileOptions {
//在这里你可以进行 Java 的版本配置,
//以便使用对应版本的一些新特性
}
productFlavors {
//在这里你可以设置你的产品发布的一些东西,
//比如你现在一共软件需要发布到不同渠道,
//且不同渠道中的包名不同,那么可以在此进行配置;
//甚至可以设置不同的 AndroidManifest.xml 文件。
xiaopao {
}
googlePlay {
}
solo {
}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//所谓ProductFlavors其实就是可定义的产品特性,
//配合 manifest merger 使用的时候就可以达成在一次编译
//过程中产生多个具有自己特性配置的版本。
//上面这个配置的作用就是,为每个渠道包产生不同的 UMENG_CHANNEL_VALUE 的值。
}
//一些依赖的框架
dependencies {
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.github.pwittchen:reactivenetwork:0.1.3'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:design:23.4.0'
compile 'pl.tajchert:waitingdots:0.2.0'
}
//声明是要使用谷歌服务框架
apply plugin: 'com.google.gms.google-services'
//第三方依赖库的本地缓存路径
task showMeCache << {
configurations.compile.each { println it }
}
//使用maven仓库。android有两个标准的library文件服务器,一个jcenter一个maven。两者毫无关系。
//jcenter有的maven可能没有,反之亦然。
//如果要使用jcenter的话就把mavenCentral()替换成jcenter()
repositories {
mavenCentral()
}
build.gradle 配置详解2
apply plugin: 'com.android.application'
def baseVername = '1.0.'
def baseVercode = 1 //单款盒子去所属App properties中配置其相应版本号
def baseBuildCnt = 1001
def appSource
def properties = new Properties()
def outputMapFile = ''
def outputApkFile = ''
def appLable = ''
def falsePkgName = ''
def defaultChannelName = "hole"
def defaultChannels = [0] //缺省只出BOX1渠道包即可
def getVersionName = { ->
//根据gitlab中的提交纪录次数,作为编译版本名字
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
def new_baseVername = properties.getProperty("baseVername")
if (new_baseVername != null) {
baseVername = new_baseVername
}
def new_baseBuildCnt = properties.getProperty("baseBuildCnt")
if (new_baseBuildCnt != null) {
baseBuildCnt = Integer.parseInt(new_baseBuildCnt)
}
println('盒子模板App加载配置:baseVername -- ' + baseVername)
return baseVername + (Integer.parseInt(stdout.toString().trim()) + baseBuildCnt)
} catch (ignored) {
def versionName = properties.getProperty("appVerName")
println('盒子模板App加载配置:versionName -- ' + versionName)
return versionName
}
}
def getVersionCode = { ->
//根据gitlab中tag标签数,作为版本代码
try {
if (defaultVersionCode > 0) {
return defaultVersionCode
}
def code = new ByteArrayOutputStream()
exec {
commandLine 'git', 'tag', '--list'
standardOutput = code
}
return code.toString().trim().split("\n").size() + baseVercode
} catch (ignored) {
def versionCode = properties.getProperty("appVerCode")
println('盒子模板App加载配置:baseVercode -- ' + versionCode)
return versionCode
}
}
def loadLocalProperties = { ->
println(' ****************** AppTemplateBox脚本执行 ******************')
if (project.properties.containsKey("game") && null != project.properties.get("game")) {
File configFile = new File(projectDir, 'properties/app-' + project.properties.get("game") + '.properties');
if (configFile.exists()) {
properties.load(configFile.newDataInputStream())
println('盒子模板App加载配置:命令行指定配置文件,' + configFile.getName())
} else {
println('盒子模板App加载配置:未定义')
}
} else {
//加载配置文件
File appSetting = new File(projectDir, 'local.properties');
if (appSetting.exists()) {
println(appSetting.absolutePath)
properties.load(appSetting.newDataInputStream())
if (properties.getProperty('config') == null)
appSetting = null
else {
properties.load(new File(projectDir, properties.getProperty('config')).newDataInputStream())
println('盒子模板App加载配置:使用本地定义(local.properties),' + properties.get("config"))
}
}
if (appSetting == null || !appSetting.exists()) {
properties.load(new File(projectDir, 'app-hole.properties').newDataInputStream())
println('盒子模板App加载配置:未定义,使用缺省配置, ')
}
}
appLable = new String(properties.getProperty("appLable").getBytes("iso-8859-1"), "utf-8");
def channel = new String(properties.getProperty("defaultChannelName").getBytes("iso-8859-1"), "utf-8");
if (channel != null) {
defaultChannelName = channel
}
outputApkFile = properties.getProperty("applicationId") + "-v" + getVersionCode() + "-" + getVersionName() + "_"
// def temp = properties.getProperty("applicationId") + "-v" + getVersionCode()+"-"+getVersionName()+".apk"
outputMapFile = outputApkFile.replace(".apk", "-map.txt")
println('盒子模板App加载配置: --- outputApkFile --- ' + outputApkFile + "\t; outputMapFile:" + outputMapFile)
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
loadLocalProperties()
lintOptions {
abortOnError = false
}
/* signingConfigs {
sign {
keyAlias 'iplay'
keyPassword 'passwd11'
storeFile file('../keystore_box_pay.jks')
storePassword 'passwd11'
}
}*/
applicationVariants.all {
def buildType = it.buildType.name
it.outputs.all {
if (buildType == "release") {
if (it.outputFile.name.endsWith("-release.apk")) {
it.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + "/release")
}
}
def apkName = "${applicationId}-${getVersionName}-${buildType}" + defaultChannels[0] + ".apk"
it.outputFileName = apkName
}
}
signingConfigs {
sign {
keyAlias = 'Redbull'
keyPassword = 'Redbull123$%^'
storeFile = file('../keystore.jks')
storePassword = 'Redbull123$%^'
}
}
defaultConfig {
// println(" --> 当前编译应用输出版本名称为:" + getVersionName())
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
applicationId properties.getProperty("applicationId")
versionCode 100102
versionName getVersionName()
println(" --> 当前编译应用输出包名为:" + applicationId)
println(" --> 当前编译应用输出版本号为:" + getVersionCode())
println(" --> 当前编译应用输出版本名称为:" + getVersionName())
def auth = properties.getProperty("ProviderPrefix")
appSource = properties.getProperty("appSource")
buildConfigField("String", "HostAppPkgName", ('"' + properties.getProperty("HostAppPkgName") + '"'))
buildConfigField("String", "PluginCenterName", ('"' + properties.getProperty("PluginCenterName") + '"'))
buildConfigField("String", "PluginName", ('"' + properties.getProperty("PluginName") + '"'))
buildConfigField("String", "AdPluginName", ('"' + properties.getProperty("AdPluginName") + '"'))
buildConfigField("String", "gameObbMd5", ('"' + properties.getProperty("gameObbMd5") + '"'))
buildConfigField("boolean", "gameIsNeedObb", properties.getProperty("gameIsNeedObb"))
buildConfigField("String", "PayPluginName", ('"' + properties.getProperty("PayPluginName") + '"'))
def modesc = new String(properties.getProperty("modDesc").getBytes("iso-8859-1"), "utf-8");
buildConfigField("String", "modDesc", ('"' + modesc + '"'))
buildConfigField("String", "AdPkgName", ('"' + properties.getProperty("AdPkgName") + '"'))
buildConfigField("String", "AdgdtAid", ('"' + properties.getProperty("AdgdtAid") + '"'))
buildConfigField("String", "AdgdtPid", ('"' + properties.getProperty("AdgdtPid") + '"'))
buildConfigField("String", "appLable", ('"' + appLable + '"'))
buildConfigField("String", "applicationId", ('"' + properties.getProperty("applicationId") + '"'))
//打点
buildConfigField("String", "talkingDataId", ('"' + properties.getProperty("talkingDataId") + '"'))
buildConfigField("String", "tracker_id", ('"' + properties.getProperty("tracker_id") + '"'))
if (properties.getProperty("falsePkgName")) {
falsePkgName = properties.getProperty("falsePkgName")
} else {
falsePkgName = properties.getProperty("applicationId")
}
//真实包名
buildConfigField("String", "falsePkgName", ('"' + falsePkgName + '"'))
//沙盒认证
buildConfigField("String", "ProviderPrefix", ('"' + auth + '"'))
buildConfigField("String", "channel", ('"' + defaultChannelName + defaultChannels[0] + '"'))
manifestPlaceholders = [
appLable : appLable,
ApplicationId : properties.getProperty("applicationId"),
SANDBOX_AUTHORITIES : auth,
SANDBOX_AUTHORITIES_0: auth + "0",
SANDBOX_AUTHORITIES_1: auth + "1",
SANDBOX_AUTHORITIES_2: auth + "2",
SANDBOX_AUTHORITIES_3: auth + "3",
SANDBOX_AUTHORITIES_4: auth + "4",
SANDBOX_AUTHORITIES_5: auth + "5",
SANDBOX_AUTHORITIES_6: auth + "6",
SANDBOX_AUTHORITIES_7: auth + "7",
SANDBOX_AUTHORITIES_8: auth + "8",
SANDBOX_AUTHORITIES_9: auth + "9",
]
ndk {
abiFilter "armeabi"
}
}
sourceSets {
def appSourcePath = appSource.toString().split(",")
appSourcePath.each { sourceItem ->
main.assets.srcDirs += ['src/' + sourceItem + '/assets']
main.res.srcDirs += ['src/' + sourceItem + '/res']
main.java.srcDirs += ['src/' + sourceItem + '/java']
}
}
buildTypes {
release {
multiDexEnabled false
minifyEnabled true
proguardFiles 'proguard-rules.pro'
rootProject.ext.allProguards.each { name ->
proguardFiles.add(name)
println(' --> 编译使用混淆文件:' + name)
}
// 移除无用的resource文件
shrinkResources true
signingConfig = signingConfigs.sign
}
debug {
signingConfig = signingConfigs.sign
multiDexEnabled false
}
}
flavorDimensions "default"
productFlavors {
def flavers = [:]
def channelTimes = defaultChannels.size()
channelTimes.times { n ->
def thisChannelNum = defaultChannels[n]
def thisChannelName = defaultChannelName + thisChannelNum
// println('thisChannelName 多渠道: '+thisChannelName)
flavers[n] = "$thisChannelName" {
buildConfigField "String", "CHANNEL", ('"' + thisChannelName + '"')
}
}
}
}
task buildMyListFile {
// group 'build'
dependsOn 'assembleRelease'
doLast {
println("=====================buildMyListFile.doLast begin .=========================")
def intoFile = project.rootDir.getAbsolutePath() + "/release/"
def fromFile = project.buildDir.getAbsolutePath() + "/outputs/apk/"
def files = file(fromFile).listFiles().sort()
files.each { File file ->
if (file.isDirectory()) {
println " *** $file.name ***"
def temDir = fromFile + file.name + "/release"
// println("============"+temDir)
def tem_file = new File(temDir)
if (tem_file.exists()) {
def files_1 = tem_file.listFiles().sort()
files_1.each { File files_2 ->
if (files_2.getName().startsWith("apk-")) {
// println " *** $files_2.name ***"
copy {
from files_2
into intoFile
}
}
}
}
}
}
println("=====================buildMyListFile.doLast success.=========================")
}
}
task buildCompressed {
dependsOn 'buildMyListFile'
doLast {
println("=====================buildCompressed.doLast begin .=========================")
println(' ********************************** ' + System.getProperties().get("os.name") + '*********************')
println(' --> 打包已完成,开始后续工作 ...')
def fromFile = project.rootDir.getAbsolutePath() + "/release/"
def files = file(fromFile).listFiles().sort()
files.each { File file ->
println " *** $file.name ***"
if (file.getName().endsWith(".apk")) {
def newOutputApkFile = file.getName()
println("=====================build.buildCompressed " + newOutputApkFile + "=========================")
task(newOutputApkFile) {
def guardJarFile = new File(project.rootDir, 'AndResGuard/AndResGuard-cli-1.2.0.jar')
//AndResGuard jar包
def guardConfigFile = new File(project.rootDir, 'AndResGuard/config.xml')
//config.xml配置文件
def originApkFile = new File(project.rootDir, "release/" + newOutputApkFile)
//需要压缩的apk
def outputDir = new File(project.rootDir, "release/compressed/") //输出的位置
def zipalign = new File(project.rootDir, 'AndResGuard/zipalign')
//AndResGuard jar包
if (System.getProperties().get("os.name").startsWith('Mac')) {
zipalign = new File(project.rootDir, 'AndResGuard/zipalign.cmd')
//AndResGuard jar包
println " --> 资源压缩:使用mac版本zipalign," + zipalign
}
def chmod = """chmod 755 ${zipalign}""".execute()
chmod.waitFor()
println(" --> java -jar ${guardJarFile} ${originApkFile} -config ${guardConfigFile} -out ${outputDir} -zipalign ${zipalign}")
if (originApkFile.exists()) {
def proc = """java -jar ${guardJarFile} ${originApkFile} -config ${
guardConfigFile
} -out ${outputDir} -zipalign ${zipalign}""".execute()
proc.waitFor();
if (outputDir.exists()) {
outputDir.eachFile {
if (it.getName().endsWith("_signed_aligned.apk")) {
println " --> 资源压缩:保留结果文件 " + it.getName() + " :" + it.length()
it.renameTo(new File(project.rootDir, "release/" + newOutputApkFile.replace(".apk", "-compressed.apk")))
} else if (it.getName().startsWith("resource_mapping") && it.getName().endsWith(".txt")) {
println " --> 资源压缩:保留混淆映射文件 " + it.getName() + " :" + it.length()
it.renameTo(new File(project.rootDir, "release/" + outputMapFile.replace(".txt", ".rsc.txt")))
} else if (it.isDirectory()) {
println " --> 资源压缩:删除多余目录 " + it.getName()
it.deleteDir()
} else {
println " --> 资源压缩:删除多余文件 " + it.getName() + " :" + it.length()
it.delete()
}
}
}
if (proc.exitValue() != 0) {
println " --> 资源压缩:失败,错误日志:\n${proc.err.text}"
}
} else {
println " --> 资源压缩:失败,缺少原始APK文件"
}
File originalInput = new File(project.rootDir, "release/" + newOutputApkFile.replace(".apk", "-compressed.apk"))
File workDir = originalInput.getParentFile()
File releaseDir = new File(workDir, "release")
if (releaseDir.exists()) {
releaseDir.deleteDir()
}
/* project.exec {
executable = 'java'
args += '-jar'
args += new File(project.projectDir, '../channelrepacker.jar').getAbsolutePath()
args += "-source=" + originalInput.getAbsolutePath()
args += '-key=' + new File(project.projectDir, '../keystore_box_pay.jks').getAbsolutePath()
args += '-keyPasswd=passwd11'
args += '-keyAlias=passwd11'
println("::" + args)
}
*/
project.exec {
executable = 'java'
args += '-jar'
args += new File(project.projectDir, '../channelrepacker.jar').getAbsolutePath()
args += "-source=" + originalInput.getAbsolutePath()
args += '-key=' + new File(project.projectDir, '../keystore.jks').getAbsolutePath()
args += '-keyPasswd=Redbull123$%^'
args += '-channel=' + thisChannelName
args += '-keyAlias=Redbull'
println("::" + args)
}
}
}
}
println("=====================buildCompressed.doLast success.=========================")
}
}
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
google()
}
dependencies {
// compile files('libs/UM_SDK-1.1.2.0.jar')
api files('libs/javabase64-1.3.1.jar')
api files('libs/pluginInterface.jar') //不能删除这个jar,否则起不来
api files('libs/TalkingData_Analytics_Android_SDK_V2.2.48.jar') //打点的jar包
api 'b.c.a:YYhhSafconn:1.0.4'
api(name: 'open_ad_sdk', ext: 'aar')
api files('libs/android-query-full.0.26.7.jar')
//定义在config.gradle数组中,基于项目名称配置的所有dependencies,方便导入
if (rootProject.ext.deps.containsKey(project.name)) {
rootProject.ext.deps[project.name].split(',').each { dep ->
println(' --> ' + project.name + '定义的依赖库:' + rootProject.ext.dependencies[dep])
api(rootProject.ext.dependencies[dep]) {
/* if (rootProject.ext.excludeModule[dep] != null) {
exclude module: rootProject.ext.excludeModule[dep]
println(' --> ' + project.name + '<移除>特定依赖库:' + rootProject.ext.excludeModule[dep])
}
if (rootProject.ext.excludeGroup[dep] != null) {
exclude group: rootProject.ext.excludeGroup[dep]
println(' --> ' + project.name + '<移除>特定依赖组:' + rootProject.ext.excludeGroup[dep])
}*/
}
}
}
}
build.gradle 依赖发行 aar
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "http://10.0.0.242:8081/artifactory/libs-release-local"
credentials {
username = "yyhd-repo"
password = "JkJheIGh28Kha0jqwUYT"
}
}
}
}
shell 中的参数怎么传递
- shell中
./gradlew collectSDK -Pflavor=gionee
- gradle脚本
def flavor = project.hasProperty('flavor') ? flavor : "common"
全局配置文件怎么传递
全局build.gradle包括:
1、Properties的读取
2、中文字符串处理
Properties properties = new Properties()
def setting0 = project.properties.get('setting')
if (setting0 == null || setting0.isEmpty()) {
InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream()
if (inputStream.readBoolean()) {
properties.load(inputStream)
setting0 = properties.getProperty('setting')
}
}
if (setting0 != null) {
properties.load(new File(rootDir.getAbsolutePath() + "/properties/" + setting0 + ".properties").newDataInputStream())
} else {
properties.load(new File(rootDir.getAbsolutePath() + "/sdk/base.properties").newDataInputStream())
}
def name = new String(properties.getProperty("name", "").getBytes("ISO-8859-1"), "utf-8")
ext {
config = [
applicationId: properties.getProperty("applicationId").toString(),
NAME : name,
TARGET0 : properties.getProperty("TARGET0").toString(),
VERSION0 : properties.getProperty("VERSION0").toString(),
SUPPORT0 : properties.getProperty("SUPPORT0").toString(),
target : properties.getProperty("target").toString(),
so : properties.getProperty("so").toString(),
versionCode : properties.getProperty("versionCode").toString(),
SupportEngine: '150'
]
dependencies = [
setting: setting0,
ui : properties.getProperty("ui").toString()
]
android = [
compileSdkVersion: 26,
buildToolsVersion: "26.0.2",
minSdkVersion : 16,
targetSdkVersion : 22
]
}
app中的build.gradle包括:
1、manifest中的${}的对象
2、BuildConfig中对象
3、全局gradle中的对象
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
applicationId applicationId0
manifestPlaceholders = [
icon : "@mipmap/ic_launcher",
NAME : NAME,
TARGET0 : TARGET0,
VERSION0 : VERSION0,
SUPPORT0 : SUPPORT0,
SupportEngine: SupportEngine
]
buildConfigField "String", "TARGET0", ('"' + TARGET0 + '"')
buildConfigField "String", "so", ('"' + so + '"')
versionCode Integer.valueOf(versionCode0)
versionName "1.0." + versionCode
ndk {
abiFilter "armeabi"
}
}
文件目录指向
还包括:
- assets
- jni
- jniLibs
- aidl
sourceSets {
main {
if (isAddShell) {
java.srcDirs = ['src/']
manifest.srcFile 'src/shell/AndroidManifest.xml'
} else if (isRewardAd) {
java.srcDirs = ['src/reward/java']
res.srcDirs = ['src/reward/res']
resources.srcDirs = ['src/reward/res']
manifest.srcFile 'src/reward/AndroidManifest.xml'
} else if (isIPlugin) {
java.srcDirs = ['src/plugin/java']
res.srcDirs = ['src/plugin/res']
resources.srcDirs = ['src/plugin/res']
manifest.srcFile 'src/plugin/AndroidManifest.xml'
}
}
}
gradle任务Task
- exec
- copy
//在执行以后
project.afterEvaluate {
tasks.forEach() {
println ' -----> it.name:' + it.name
if (it.name.equalsIgnoreCase('assembleRelease')) {
it.doLast {
println ' -----> all task:====================================Release'
println ' outputApkFileName' + outputApkFileName
def apkPath = project.buildDir.absolutePath + '/outputs/apk/release/' + outputApkFileName
println apkPath
project.exec {
executable = 'java'
args += '-jar'
args += shelltoolspaht
args += apkPath
args += shellapkapth
out
println("args = " + args)
}
def intoFile = project.rootDir.getAbsolutePath() + "/release/"
def fromFile = project.buildDir.getAbsolutePath() + "/outputs/apk/release/"
File file1 = new File(intoFile);
if (!file1.exists())
file1.mkdir()
def files = file(fromFile).listFiles().sort()
files.each { File file ->
if (file.isDirectory()) {
def files_1 = file.listFiles().sort()
files_1.each { File files_2 ->
if (files_2.getName().contentEquals(outputApkFileName)) {
// files_2.renameTo(intoFile+chName+outputFileName)
copy {
from files_2
into intoFile
println(' --> cpy apk ' + files_2);
}
}
}
}
}
println("=====================buildMyListFile.doLast success.=========================")
}
}
if (it.name.equalsIgnoreCase('assembleDebug')) {
it.doLast {
println ' -----> all task:====================================Debug'
println ' outputApkFileName' + outputApkFileName
def apkPath = project.buildDir.absolutePath + '/outputs/apk/debug/' + outputApkFileName
println apkPath
project.exec {
executable = 'java'
args += '-jar'
args += shelltoolspaht
args += apkPath
args += shellapkapth
out
println("args = " + args)
}
}
}
}
}