指定 混淆字典
在app的gralde里配置混淆字典
-obfuscationdictionary dict.txt#外部字典
-classobfuscationdictionary dict.txt #類字典
-packageobfuscationdictionary dict.txt #包字典
dict.txt 文件內(nèi)容類似這樣的:
zguqnx
mvdmuyh
wmws
jwomtp
nhmhn
zvlogo
pomcwh
bhdnzul
osxbj
gojb
ctvkrg
srmar
sgkarnqi
byghdn
tvebtxw
uxdhno
qmjac
pgxasjnc
ezfb
tuoe
pzdo
寫了一個task
/**
* 生成字典Task
*/
task geneDictTask {
doFirst{
def dictPath = rootDir.getAbsolutePath()+'/app/dict.txt'
def random = new Random()
def lowercase = "abcdefghijklmnopqrstuvwxyz"
def wordList = new HashSet()
for (int i=0;i<10000;i++){
def word = new StringBuilder()
def wordLength = random.nextInt(5)+4
for (int j=0;j<wordLength;j++){
word.append(lowercase.charAt(random.nextInt(lowercase.length())))
}
wordList.add(word.toString())
}
def f = new File(dictPath)
f.getParentFile().mkdirs()
f.withWriter("UTF-8") {
it.write(wordList.join(System.lineSeparator()))
}
}
}
//
xmlClassGuard
xmlClassGuard {
/*
* 是否查找約束布局的constraint_referenced_ids屬性的值,并添加到AabResGuard的白名單中,
* true的話,要求你在XmlClassGuard前依賴AabResGuard插件,默認(rèn)false
*/
// findConstraintReferencedIds = true
//用于增量混淆的 mapping 文件
mappingFile = file("xml-class-mapping.txt")
//更改manifest文件的package屬性,即包名
packageChange = ["com.DOTLESS.gala": "com.DOTLESS.gala"]
//移動目錄
moveDir = ["com.DOTLESS.gala": "com.DOTLESS.gala"]
}
批量修改文件名文章來源:http://www.zghlxwxcb.cn/news/detail-493055.html
ext {
//需要批量重命名的Been路徑
renameBeenPath = "src/main/java/com/DOTLESS/gala/bean"
//Been對象名字以什么字符串結(jié)尾, 默認(rèn)Been, 例如設(shè)為Beax, 則所有Been都會以Beax結(jié)尾, 如GoodsBeax.kt
beenNameSuffix = "Bear"
//Been名字的前綴, 例如KoGoodsBeen
beenPrefix = "Ko"
//Been對象 Been的前面加的字符串 KoGoodsFishBeen
beenMidfix = "Fish"
//特殊的Been比配
// specialBeensMatcher = ["**/*Been.kt", "**/*Been.java"]
}
task renameBeenProcesser {
doLast {
FileTree beenTree = fileTree(renameBeenPath) {
include '**/*.java'
include '**/*.kt'
// include specialBeensMatcher
}
def start = System.currentTimeMillis()
println(">>>>>> renameBeenProcesser start")
beenTree.each { File beenFile ->
//println(beenFile.path + " Processing...")
def sname = beenFile.name
def fileEx = sname.substring(sname.lastIndexOf("."))
sname = sname.replace(fileEx, "")
def tName = ""
// if (sname.endsWith("Been")) {
// tName = beenPrefix + sname.replace("Been", beenMidfix + beenNameSuffix)
// } else if (sname.endsWith("Bean")) {
// tName = beenPrefix + sname.replace("Bean", beenMidfix + beenNameSuffix)
// } else {
tName = beenPrefix + sname + beenMidfix + beenNameSuffix
// }
beenFile.renameTo(beenFile.parentFile.path + File.separator + tName + fileEx)
//生成一個文件樹,替換import后面的路徑
FileTree processTree = fileTree("src") {
include '**/*.java'
include '**/*.kt'
include '**/layout/*.xml'
}
processTree.each { File f ->
ImportBeenReplacer(f.path, sname, tName)
}
}
def cost = (System.currentTimeMillis() - start) / 1000
println(">>>>>> renameBeenProcesser end(cost:${cost}s)")
}
}
//替換有導(dǎo)入目標(biāo)been的文件內(nèi)容
def ImportBeenReplacer(String filePath, sourceBeenName, targetBeenName) {
def readerString = ""
def hasReplace = false
def xml = filePath.endsWith(".xml")
file(filePath).withReader('UTF-8') { reader ->
reader.eachLine {String it ->
if (it.find(sourceBeenName)) {
if (xml) {
//println("###$filePath: $sourceBeenName->$targetBeenName")
it = it.replaceAll("(?<![a-zA-Z0-9]+)(?<=[\\.]+)$sourceBeenName(?=[ \"\\./>]*)(?![a-zA-Z0-9]+)", targetBeenName)
} else {
it = it.replaceAll("(?<![a-zA-Z0-9]+)(?<=[ \\.<:\\s\\,(]+)$sourceBeenName(?=[ \"\\.>\\?\\:\\(]*)(?![a-zA-Z0-9]+)", targetBeenName)
}
hasReplace = true
}
readerString <<= it
readerString << '\n'
}
}
if (hasReplace) {
if(readerString.toString().endsWith("\n")) readerString = readerString.subSequence(0, readerString.length() - 1)
//替換文件
//println(filePath + " has replace been.")
file(filePath).withWriter('UTF-8') {
writer ->
writer.append(readerString)
}
}
}
androidJunkCode 添加垃圾代碼文章來源地址http://www.zghlxwxcb.cn/news/detail-493055.html
androidJunkCode {
def config = {
packageBase = "com.dotless.xthv"
packageCount = 15
activityCountPerPackage = 3
excludeActivityJavaFile = false
otherCountPerPackage = 15
methodCountPerClass = 10
resPrefix = "xthv_"
drawableCount = 10
stringCount = 10
}
variantConfig {
devDebug config //和productFlavors里的名字一樣,注意不能是大寫,不然會報錯
devRelease config
publishDebug config
publishRelease config
}
}
到了這里,關(guān)于Android 馬甲包 google市場混淆技術(shù)方案的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!