Skip to content

Commit 885e8e7

Browse files
committed
Update debug.gradle for in-app dex resource extraction
1 parent b9c9c77 commit 885e8e7

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
minifyEnabled false
1717
shrinkResources false
1818
zipAlignEnabled true
19-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
proguardFiles 'proguard-rules.pro'
2020
}
2121
}
2222

@@ -57,6 +57,7 @@ project.ext.appInfo = [
5757
WeChat: "com.tencent.mm",
5858
UnionPay: "com.unionpay",
5959
]
60+
project.ext.moduleFrameworks = ['riru', 'zygisk']
6061

6162
apply from: 'debug.gradle'
6263
apply from: 'update-json.gradle'

app/debug.gradle

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,90 @@
1-
def ADB_PATH = "${android.getSdkDirectory()}/platform-tools/adb"
1+
ext {
2+
adbPath = "${android.getSdkDirectory()}/platform-tools/adb"
3+
buildXposed = false
4+
}
5+
def adbPushToAppFiles(dexPath, targetName, targetPackage) {
6+
exec {
7+
executable = adbPath
8+
args = ['push', dexPath, "/data/local/tmp/${targetName}"]
9+
}
10+
exec {
11+
executable = adbPath
12+
args = ["shell", "su", "-c",
13+
""""NAME=${targetName} && \
14+
mv /data/local/tmp/\\\$NAME /data/data/$targetPackage/files/\\\$NAME && \
15+
chmod 444 /data/data/$targetPackage/files/\\\$NAME && \
16+
UID=\\\$(stat -c "%u" /data/data/$targetPackage) && \
17+
GID=\\\$(stat -c "%g" /data/data/$targetPackage) && \
18+
chown \\\$UID:\\\$GID /data/data/$targetPackage/files/\\\$NAME && \
19+
true" """]
20+
}
21+
}
22+
223
project.ext.appInfo.each {entry ->
324
def name = entry.key
425
def packageName = entry.value
526
def stopTask = tasks.create(name: "stop$name", type: Exec) {
627
doFirst { println "Stop $name..." }
7-
executable = ADB_PATH
28+
executable = adbPath
829
args = ['shell', "am force-stop $packageName"]
930
}
1031
def startTask = tasks.create(name: "start$name", dependsOn: [stopTask], type: Exec) {
1132
doFirst { println "Start $name..." }
12-
executable = ADB_PATH
33+
executable = adbPath
1334
args = ['shell', "sleep 3;am start \$(cmd package resolve-activity --brief ${packageName} | tail -n 1)"]
1435
}
1536
def debugXposedTask = tasks.create(name: "debug${name}Xposed", dependsOn: ["installDebug", stopTask], type: Exec) {
16-
executable = ADB_PATH
37+
executable = adbPath
1738
args = ['shell', "package=${android.defaultConfig.applicationId}&& cp -f \$(pm path \$package| cut -d: -f2) /data/local/tmp/\$package.apk && chmod 777 /data/local/tmp/\$package.apk"]
1839
}
1940
debugXposedTask.finalizedBy(startTask)
20-
def debugRiruTask = tasks.create(name: "debug${name}Riru", dependsOn: ["mergeDexDebug"], type: Exec) {
21-
def classDexPath = new File(project.buildDir, "intermediates/dex/debug/mergeDexDebug/classes.dex").absolutePath
22-
executable = ADB_PATH
23-
args = ['push', classDexPath, "/data/local/tmp/libriru-module-xfingerprint-pay-${name.toLowerCase()}.debug.dex"]
24-
doLast {
25-
exec {
26-
executable = ADB_PATH
27-
args = ["shell", "chmod", "a-w", "/data/local/tmp/libriru-module-xfingerprint-pay-${name.toLowerCase()}.debug.dex"]
41+
}
42+
43+
android.applicationVariants.all { variant ->
44+
variant.getCompileConfiguration().resolutionStrategy {
45+
def buildType = variant.getBuildType()
46+
def buildTypeName = buildType.name
47+
def buildTypeNameCapitalize = buildTypeName.capitalize()
48+
def isMinifyEnabled = buildType.isMinifyEnabled()
49+
def minifyTask = tasks.findByName("minifyReleaseWithR8")
50+
def dexTask = tasks.findByName(isMinifyEnabled ? "minify${buildTypeNameCapitalize}WithR8" : "mergeDex${buildTypeNameCapitalize}")
51+
if (minifyTask) {
52+
minifyTask.doFirst {
53+
if (buildXposed) {
54+
return
55+
}
56+
def aaptRulesFile = file("${buildDir}/intermediates/aapt_proguard_file/release/aapt_rules.txt")
57+
if (aaptRulesFile.exists()) {
58+
aaptRulesFile.delete()
59+
}
2860
}
2961
}
30-
}
31-
debugRiruTask.finalizedBy(startTask)
32-
def debugZygiskTask = tasks.create(name: "debug${name}Zygisk", dependsOn: ["mergeDexDebug"], type: Exec) {
33-
def classDexPath = new File(project.buildDir, "intermediates/dex/debug/mergeDexDebug/classes.dex").absolutePath
34-
executable = ADB_PATH
35-
args = ['push', classDexPath, "/data/local/tmp/libzygisk-module-xfingerprint-pay-${name.toLowerCase()}.debug.dex"]
36-
doLast {
37-
exec {
38-
executable = ADB_PATH
39-
args = ["shell", "chmod", "a-w", "/data/local/tmp/libzygisk-module-xfingerprint-pay-${name.toLowerCase()}.debug.dex"]
62+
tasks.create(name: "assemble${buildTypeNameCapitalize}Xposed", dependsOn: [variant.assemble]) {
63+
buildXposed = true
64+
}
65+
66+
project.ext.appInfo.each {entry ->
67+
def name = entry.key
68+
def packageName = entry.value
69+
def startTask = tasks.findByName("start$name")
70+
def stopTask = tasks.findByName("stop$name")
71+
72+
project.ext.moduleFrameworks.each { framework ->
73+
def moduleTask = tasks.create(name: "${buildTypeName}${name}${framework.capitalize()}", dependsOn: [dexTask]) {
74+
doLast {
75+
def dexPath = fileTree(dir: new File(project.buildDir, "intermediates/dex/${buildTypeName}"), include: '**/classes.dex').files.sort { it.lastModified() }.last().absolutePath
76+
adbPushToAppFiles(dexPath, "${framework}-module-xfingerprint-pay-${name.toLowerCase()}.dex", packageName)
77+
}
78+
}
79+
moduleTask.finalizedBy(startTask)
4080
}
4181
}
42-
}
43-
debugZygiskTask.finalizedBy(startTask)
44-
}
4582

46-
android.applicationVariants.all { variant ->
47-
variant.getCompileConfiguration().resolutionStrategy {
4883
if (variant.install != null) {
4984
variant.install.doLast {
5085
println "Running app..."
5186
exec {
52-
executable = ADB_PATH
87+
executable = adbPath
5388
args = ['shell', "monkey -p ${variant.applicationId} -c android.intent.category.LAUNCHER 1"]
5489
}
5590
}

0 commit comments

Comments
 (0)