Skip to content

Commit

Permalink
Changed: Made Keycode enum generation automatic for CompileSdk versio…
Browse files Browse the repository at this point in the history
…n, added task to ensure sources for that version are installed.
  • Loading branch information
tareksander committed Feb 15, 2024
1 parent b8bedec commit 415cdbc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ protobuf {
class UpdateProtoAction implements Action {
String projectDir
String sdkDirectory
String compileSdk;

UpdateProtoAction(String projectDir, String sdkDirectory) {
UpdateProtoAction(String projectDir, String sdkDirectory, String compileSdk) {
this.projectDir = projectDir
this.sdkDirectory = sdkDirectory
this.compileSdk = compileSdk
}


@Override
void execute(Object o) {
File protoFile = Paths.get(projectDir, "src", "main", "proto", "GUIProt0.proto").toFile()
File keyEventFile = Paths.get(sdkDirectory, "sources", "android-33", "android", "view", "KeyEvent.java").toFile()
File keyEventFile = Paths.get(sdkDirectory, "sources", "android-"+ compileSdk, "android", "view", "KeyEvent.java").toFile()
String[] lines = keyEventFile.readLines()
String codes = lines.findAll {
it.stripLeading().startsWith("public static final int KEYCODE_")
Expand All @@ -61,13 +63,15 @@ class UpdateProtoAction implements Action {
}

tasks.register("gen-proto-keycodes") {
actions.push(new UpdateProtoAction(projectDir.path, android.sdkDirectory.path))
actions.push(new UpdateProtoAction(projectDir.path, android.sdkDirectory.path, android.compileSdk.toString()))
}


tasks.register("ensure-sources", Exec.class) {
it.commandLine(Paths.get(android.sdkDirectory.path, "cmdline-tools", "latest", "bin", "sdkmanager").toString(), "sources;android-" + android.compileSdk.toString())
}

tasks.preBuild {
dependsOn("gen-proto-keycodes")
dependsOn("gen-proto-keycodes", "ensure-sources")
}

android {
Expand Down

0 comments on commit 415cdbc

Please sign in to comment.