From 714feeb9a79e29fb4d8fa3626e539a2d758c66b6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 7 Sep 2021 04:02:29 -0700 Subject: [PATCH] Support building on case insensitive filesystems Fix #4643, close #4641 --- buildSrc/src/main/java/Codegen.kt | 20 ++++++++++++------- .../topjohnwu/magisk/DownloadActivity.java | 8 ++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/buildSrc/src/main/java/Codegen.kt b/buildSrc/src/main/java/Codegen.kt index d56043acf..b8df250c0 100644 --- a/buildSrc/src/main/java/Codegen.kt +++ b/buildSrc/src/main/java/Codegen.kt @@ -10,10 +10,12 @@ import javax.crypto.Cipher import javax.crypto.CipherOutputStream import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec +import kotlin.random.asKotlinRandom -// Set non-zero value here to fix the random seed to create reproducible builds +// Set non-zero value here to fix the random seed for reproducible builds const val RAND_SEED = 0 private lateinit var RANDOM: Random +private val kRANDOM get() = RANDOM.asKotlinRandom() private val c1 = mutableListOf() private val c2 = mutableListOf() @@ -195,15 +197,19 @@ fun genStubManifest(srcDir: File, outDir: File): String { names.addAll(c3.subList(0, 10)) names.shuffle(RANDOM) + // Decapitalize as older Android versions do not allow capitalized package names + // Distinct by lower case to support case insensitive file systems + val pkgNames = names.map { it.decapitalize(Locale.ROOT) } + .distinctBy { it.toLowerCase(Locale.ROOT) } + var idx = 0 - fun genCmpName(): String { - val name = "${names[idx++]}.${names[idx++]}" - return name[0].toLowerCase() + name.substring(1) - } + fun genCmpName() = "${pkgNames[idx++]}.${names.random(kRANDOM)}" fun genClass(clzName: String, type: String) { val (pkg, name) = clzName.split('.') - PrintStream(File(mainPkgDir, "$name.java")).use { + val pkgDir = File(outDir, pkg) + pkgDir.mkdir() + PrintStream(File(pkgDir, "$name.java")).use { it.println("package $pkg;") it.println("public class $name extends com.topjohnwu.magisk.$type {}") } @@ -254,7 +260,7 @@ fun genEncryptedResources(res: File, outDir: File) { it.delete() txt } - File(mainPkgDir, "A.java").writeText(r.replace("class R", "class A")) + File(mainPkgDir, "R2.java").writeText(r.replace("class R", "class R2")) // Generate iv and key val iv = ByteArray(16) diff --git a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java index 7206b9cee..444edb03f 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java @@ -4,10 +4,10 @@ import static android.R.string.no; import static android.R.string.ok; import static android.R.string.yes; import static com.topjohnwu.magisk.DelegateApplication.dynLoad; -import static com.topjohnwu.magisk.A.string.dling; -import static com.topjohnwu.magisk.A.string.no_internet_msg; -import static com.topjohnwu.magisk.A.string.relaunch_app; -import static com.topjohnwu.magisk.A.string.upgrade_msg; +import static com.topjohnwu.magisk.R2.string.dling; +import static com.topjohnwu.magisk.R2.string.no_internet_msg; +import static com.topjohnwu.magisk.R2.string.relaunch_app; +import static com.topjohnwu.magisk.R2.string.upgrade_msg; import android.app.Activity; import android.app.AlertDialog;