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 也可以安裝次模式