From 05123c70682e5988ad5f0ff111f97b66a87d8806 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Thu, 19 Oct 2023 22:00:03 +0200 Subject: [PATCH] Reproducible classes2.dex Signed-off-by: Balazs Toldi --- app/build.gradle | 30 ++++++++++++++++++++++++++++++ build.gradle | 9 ++++++--- scripts/fixEventBus.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 scripts/fixEventBus.py diff --git a/app/build.gradle b/app/build.gradle index c9d7175e..7092000d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -98,6 +98,31 @@ android { doNotStrip '**/*.so' } namespace 'eu.toldi.infinityforlemmy' + + + task rearrangeClass(type: Exec) { + commandLine 'python', '../scripts/fixEventBus.py' + } + + applicationVariants.all { variant -> + if (variant.name == 'release') { + task("compileSingleFile${variant.name.capitalize()}", type: JavaCompile, dependsOn: rearrangeClass) { + def filePath = project.rootDir.absolutePath + '/app/build/generated/ap_generated_sources/release/out/eu/toldi/infinityforlemmy/' + source = files(filePath) + includes = ["**/EventBusIndex.java"] + classpath = variant.getCompileClasspath() + files(project.rootDir.absolutePath + '/app/build/intermediates/javac/release/classes') + destinationDir = file("$buildDir/intermediates/javac/release/classes") + } + + tasks.withType(JavaCompile).all { task -> + if (task.name == 'compileReleaseJavaWithJavac') { + task.finalizedBy "compileSingleFile${variant.name.capitalize()}" + } + } + } + } + + } dependencies { @@ -246,3 +271,8 @@ dependencies { //debugImplementation 'com.squareup.leakcanary:leakcanary-android:x.y' } + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4eb65b79..b781a2ba 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,9 @@ allprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir -} + +tasks.whenTaskAdded { + if (name.contains("ArtProfile")) { + enabled = false + } +} \ No newline at end of file diff --git a/scripts/fixEventBus.py b/scripts/fixEventBus.py new file mode 100644 index 00000000..b927f7a6 --- /dev/null +++ b/scripts/fixEventBus.py @@ -0,0 +1,32 @@ +import re +import sys + + +def rearrange(filename): + with open(filename, 'r') as file: + content = file.read() + + # Regex to find the blocks of code to rearrange + pattern = re.compile(r'(putIndex\(new SimpleSubscriberInfo\(.*?\)\);)', re.DOTALL) + blocks = pattern.findall(content) + + # Sort blocks based on the class names mentioned in SimpleSubscriberInfo instances + sorted_blocks = sorted(blocks, key=lambda x: re.search(r'SimpleSubscriberInfo\((.*?),', x).group(1)) + + # Replace the original blocks with the sorted blocks + sorted_content = pattern.sub(lambda match: sorted_blocks.pop(0), content) + + with open(filename, 'w') as file: + file.write(sorted_content) + + +# Project root relative to the script +project_root = __file__[:-len('/scripts/fixEventBus.py')] + +path = './build/generated/ap_generated_sources/release/out/eu/toldi/infinityforlemmy/EventBusIndex.java' + +# Print the path to the file to stderr +print(path, file=sys.stderr) + +# Call the function with the path to EventBusIndex.java +rearrange(path)