Skip to content

Commit

Permalink
Adjust proguard for Android R8
Browse files Browse the repository at this point in the history
1. Use JDK 21
2. Update android plugins for JDK 21
3. Update gradle wrapper

The new R8 engine will change more class names than before, we thus
need to save those needed ones.

Currently, due to a bug of Android Application Gradle Plugin 8.4, i.e,
com.android.application > com.android.application.gradle.plugin, one can
not perform the task optimizeReleaseResources without errors.
To see the bug, run
`./gradlew --stacktrace --info optimizeZygiskReleaseResources`
It shows that the commnd `aapt2` has wrong working directory.
Hence, we skip this task.
  • Loading branch information
JingMatrix committed May 14, 2024
1 parent f3beb86 commit 69f7390
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
java-version: "21"

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.project
.settings
*.iml
.gradle
/local.properties
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ val androidTargetSdkVersion by extra(34)
val androidMinSdkVersion by extra(27)
val androidBuildToolsVersion by extra("34.0.0")
val androidCompileSdkVersion by extra(34)
val androidCompileNdkVersion by extra("26.1.10909125")
val androidSourceCompatibility by extra(JavaVersion.VERSION_17)
val androidTargetCompatibility by extra(JavaVersion.VERSION_17)
val androidCompileNdkVersion by extra("26.3.11579264")
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)

tasks.register("Delete", Delete::class) {
delete(rootProject.layout.buildDirectory)
Expand Down
16 changes: 6 additions & 10 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
-keep class android.** { *; }
-keep class de.robv.android.xposed.** {*;}
-keep class io.github.libxposed.** {*;}
-keep class org.lsposed.lspd.core.* {*;}
-keep class org.lsposed.lspd.impl.LSPosedBridge$NativeHooker {*;}
-keep class org.lsposed.lspd.impl.LSPosedBridge$HookerCallback {*;}
-keep class org.lsposed.lspd.util.Hookers {*;}

-keepattributes RuntimeVisibleAnnotations
-keep class android.** { *; }
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}
Expand All @@ -15,15 +20,6 @@
@io.github.libxposed.api.annotations.BeforeInvocation <methods>;
@io.github.libxposed.api.annotations.AfterInvocation <methods>;
}
-keepclassmembers class org.lsposed.lspd.impl.LSPosedBridge$NativeHooker {
<init>(java.lang.reflect.Executable);
callback(...);
}
-keepclassmembers class org.lsposed.lspd.impl.LSPosedBridge$HookerCallback {
final *** beforeInvocation;
final *** afterInvocation;
HookerCallback(...);
}
-assumenosideeffects class android.util.Log {
public static *** v(...);
public static *** d(...);
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.2.1"
kotlin = "1.9.22"
nav = "2.7.6"
agp = "8.4.0"
kotlin = "1.9.23"
nav = "2.7.7"
appcenter = "5.0.4"
libxposed = "100"
glide = "4.16.0"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
18 changes: 16 additions & 2 deletions magisk-loader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.filters.ReplaceTokens
import java.io.ByteArrayOutputStream
import java.security.MessageDigest
import com.android.build.gradle.internal.tasks.OptimizeResourcesTask

plugins {
alias(libs.plugins.agp.app)
Expand Down Expand Up @@ -200,7 +201,8 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
rename(".*\\.apk", "daemon.apk")
}
into("lib") {
from(layout.buildDirectory.dir("intermediates/stripped_native_libs/$variantCapped/out/lib")) {
val libDir = variantCapped + "/strip${variantCapped}DebugSymbols"
from(layout.buildDirectory.dir("intermediates/stripped_native_libs/$libDir/out/lib")) {
include("**/liblspd.so")
}
}
Expand Down Expand Up @@ -303,7 +305,7 @@ val pushDaemonNative = task<Exec>("pushDaemonNative") {
}
outputStream.toString().trim()
}
workingDir(project(":daemon").layout.buildDirectory.dir("intermediates/stripped_native_libs/debug/out/lib/$abi"))
workingDir(project(":daemon").layout.buildDirectory.dir("intermediates/stripped_native_libs/debug/stripDebugDebugSymbols/out/lib/$abi"))
}
commandLine(adb, "push", "libdaemon.so", "/data/local/tmp/libdaemon.so")
}
Expand Down Expand Up @@ -343,5 +345,17 @@ task("reRunApp") {
finalizedBy(reRunDaemon)
}

tasks.withType(OptimizeResourcesTask::class.java) {
onlyIf { false }
// doFirst {
// val variantCapped = name.substring(8, name.length - 9)
// val working_dir = layout.buildDirectory.dir("intermediates/optimized_processed_res/$variantCapped").get().getAsFile()
// val subDir = File(working_dir, name)
// if (subDir.isDirectory()) {
// subDir.copyRecursively(working_dir, true)
// }
// }
}

evaluationDependsOn(":app")
evaluationDependsOn(":daemon")
2 changes: 2 additions & 0 deletions magisk-loader/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
-repackageclasses
-allowaccessmodification
-dontwarn org.slf4j.impl.StaticLoggerBinder
-dontwarn org.lsposed.lspd.core.*
-dontwarn org.lsposed.lspd.util.Hookers

0 comments on commit 69f7390

Please sign in to comment.