5 Star 38 Fork 6

Theone / TheBase

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
build.gradle 2.58 KB
一键复制 编辑 原始数据 按行查看 历史
Theone 提交于 2020-11-12 14:41 . 添加混淆规则
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from:"baseConfigs.gradle"
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
/***** 使用Gradle assembleRelease 打包,以下代码为将打包好的APK文件复制到项目目录下的apks文件夹下 *******/
subprojects(){
// 这里获取到assembleRelease和assembleDebug的task任务
//注意这里使用tasks.getByName("assembleRelease")会报错,找不到这个task
def releaseTasks = project.getTasksByName("assembleRelease",false)
copyApkFile(releaseTasks, project)
}
def copyApkFile(Set<Task> tasks , Project project) {
for (task in tasks) {
def projectPath = project.getProjectDir().getAbsolutePath() // 项目地址
def copyPath = projectPath + "\\build\\outputs\\apk\\release" // 复制的地址
def target = rootProject.getProjectDir().getAbsolutePath() + "\\apks" // 目标地址
println "=================== assemble release path = $copyPath"
def file = new File(copyPath)
//在生成此apk之前,如果先将之前存在生成的apk则删除
if (file.exists()) {
def result = delete(copyPath)
println "=================== clear before create $copyPath + ---- $result"
}
task.doLast {
if (file.exists()) {
//将生成的apk拷贝出来
copy{ //copy是gradle中的project提供的方法,用于拷贝,里面有两个特定的属性
//from srcDir , into desDir (当这个目录不存在的时候会尝试创建这个文件夹)
println "=================== copy file from ---- "+copyPath+" to ---- "+target
from copyPath
into target
}
println "=================== delete after copy -------------------$copyPath "
// 拷贝完后删除
delete(copyPath)
}
}
}
}
Android
1
https://gitee.com/theoneee/TheBase.git
git@gitee.com:theoneee/TheBase.git
theoneee
TheBase
TheBase
master

搜索帮助