Reproducible classes2.dex

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2023-10-19 22:00:03 +02:00
parent 908f294130
commit 05123c7068
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
3 changed files with 68 additions and 3 deletions

View File

@ -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
}

View File

@ -26,6 +26,9 @@ allprojects {
}
}
task clean(type: Delete) {
delete rootProject.buildDir
tasks.whenTaskAdded {
if (name.contains("ArtProfile")) {
enabled = false
}
}

32
scripts/fixEventBus.py Normal file
View File

@ -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)