Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Min API" setting #69

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ suspend fun buildAndDisassemble(
toolPaths: ToolPaths,
source: String,
r8rules: String,
minApi: Int,
instructionSets: Map<ISA, Boolean>,
onByteCode: (CodeContent) -> Unit,
onDex: (CodeContent) -> Unit,
Expand Down Expand Up @@ -150,7 +151,7 @@ suspend fun buildAndDisassemble(
launch(ui) { updater.advance("") }
}

val dexCompiler = DexCompiler(toolPaths, directory, r8rules)
val dexCompiler = DexCompiler(toolPaths, directory, r8rules, minApi)

val dex = dexCompiler.buildDex(optimize, keepEverything)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ private fun FrameWindowScope.MainMenu(
explorerState.toolPaths,
sourceTextArea.text,
explorerState.r8Rules,
explorerState.minApi,
instructionSets,
onByteCodeUpdate,
onDexUpdate,
Expand Down
5 changes: 5 additions & 0 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun Settings(
val androidHome = rememberTextFieldState(state.androidHome)
val kotlinHome = rememberTextFieldState(state.kotlinHome)
val r8rules = rememberTextFieldState(state.r8Rules)
val minApi = rememberTextFieldState(state.minApi.toString())
val indent = rememberTextFieldState(state.indent.toString())
val lineNumberWidth = rememberTextFieldState(state.lineNumberWidth.toString())
val decompileHiddenIsa = remember { mutableStateOf(state.decompileHiddenIsa) }
Expand All @@ -47,6 +48,7 @@ fun Settings(
androidHome.text.toString(),
kotlinHome.text.toString(),
r8rules.text.toString(),
minApi.text.toString(),
indent.text.toString(),
lineNumberWidth.text.toString(),
decompileHiddenIsa.value
Expand All @@ -61,6 +63,7 @@ fun Settings(
IntSetting("Decompiled code indent: ", indent, minValue = 2)
IntSetting("Line number column width: ", lineNumberWidth, minValue = 1)
MultiLineStringSetting("R8 rules: ", r8rules)
IntSetting("Min API: ", minApi, minValue = 1)
BooleanSetting("Decompile hidden instruction sets", decompileHiddenIsa)
Spacer(modifier = Modifier.height(8.dp))
Buttons(saveEnabled = toolPaths.isValid, onSaveClick, onDismissRequest)
Expand All @@ -87,13 +90,15 @@ private fun ExplorerState.saveState(
androidHome: String,
kotlinHome: String,
r8Rules: String,
minApi: String,
indent: String,
lineNumberWidth: String,
decompileHiddenIsa: Boolean,
) {
this.androidHome = androidHome
this.kotlinHome = kotlinHome
this.r8Rules = r8Rules
this.minApi = minApi.toIntOrNull() ?: 21
this.indent = indent.toIntOrNull() ?: 4
this.lineNumberWidth = lineNumberWidth.toIntOrNull() ?: 4
this.decompileHiddenIsa = decompileHiddenIsa
Expand Down
5 changes: 3 additions & 2 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private const val KotlinHome = "KOTLIN_HOME"
private const val Optimize = "OPTIMIZE"
private const val KeepEverything = "KEEP_EVERYTHING"
private const val R8Rules = "R8_RULES"
private const val MinApi = "MIN_API"
private const val AutoBuildOnStartup = "AUTO_BUILD_ON_STARTUP"
private const val Presentation = "PRESENTATION"
private const val ShowLineNumbers = "SHOW_LINE_NUMBERS"
Expand Down Expand Up @@ -58,6 +59,7 @@ class ExplorerState {
var optimize by BooleanState(Optimize, true)
var keepEverything by BooleanState(KeepEverything, true)
var r8Rules by StringState(R8Rules, "")
var minApi by IntState(MinApi, 21)
var autoBuildOnStartup by BooleanState(AutoBuildOnStartup, false)
var presentationMode by BooleanState(Presentation, false)
var showLineNumbers by BooleanState(ShowLineNumbers, false)
Expand All @@ -80,8 +82,7 @@ class ExplorerState {
toolPaths = createToolPaths()
}

private fun createToolPaths() =
ToolPaths(directory, Path.of(androidHome.toString()), Path.of(kotlinHome.toString()))
private fun createToolPaths() = ToolPaths(directory, Path.of(androidHome), Path.of(kotlinHome))

private inner class BooleanState(key: String, initialValue: Boolean) :
SettingsState<Boolean>(key, initialValue, { toBoolean() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.*

class DexCompiler(private val toolPaths: ToolPaths, private val outputDirectory: Path, private val r8rules: String) {
class DexCompiler(private val toolPaths: ToolPaths, private val outputDirectory: Path, private val r8rules: String, private val minApi: Int) {
suspend fun buildDex(optimize: Boolean, keepEverything: Boolean): ProcessResult {
return process(*buildDexCommand(optimize, keepEverything), directory = outputDirectory)
}
Expand All @@ -45,7 +45,7 @@ class DexCompiler(private val toolPaths: ToolPaths, private val outputDirectory:
add(toolPaths.d8.toString())
add(if (optimize) "com.android.tools.r8.R8" else "com.android.tools.r8.D8")
add("--min-api")
add("21")
add(minApi.toString())
if (optimize) {
add("--pg-conf")
add("rules.txt")
Expand Down