title: gradle编译完成Copy mapping文件
date: 2021-05-15 12:56:53
categories:
- Android
tags: - Gradle
背景:release版本混淆打开以后需要copy出mapping文件上传给第三方平台。方便crash分析。
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
使用gradle4.1.3 测试
android.applicationVariants.all { variant ->
def buildType = variant.buildType.name
tasks.all {
def mappingDir = "${buildDir}/outputs/mapping/${variant.flavorName}${buildType.capitalize()}"
def mappingPath = "${mappingDir}/mapping.txt"
def mappingFiles = [mappingPath]
def mappingOtherPath = "${buildDir}/outputs/mapping/${variant.flavorName}/${buildType}"
if (variant.buildType.name == 'debug') {
it.doLast {
copy {
mappingFiles.each {
if (file(it).exists()) {
from it
into mappingOtherPath
}
}
}
}
}
}
}
Copy so 也可以安装次模式