Skip to content

Commit 0b593d5

Browse files
authored
feature: enable to set android min api (#295)
* Add androidMinApi parameter to gradle plugin to enable specify --min-api argument of d8 tool * Add all dex files to main dex jar
1 parent c6d222d commit 0b593d5

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

docs/src/doc/user-guide/exporting.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ On android, we do not embed a JVM, we use the existing ART provided by the OS. I
6363
}
6464
```
6565

66+
- Setting the `androidMinApi` (equivalent to `--min-api` argument of `d8` tool), default is `21`:
67+
```kt
68+
godot {
69+
androidMinApi = 22
70+
}
71+
```
72+
6673
!!! warning
6774
Similar to the desktop targets, the game copies the needed jar files to the `user://` directory upon first execution or if the files have changed. On android this is the applications `files` folder. If you do IO operations on Android, never empty the whole `files` folder! Only delete what you have added or exclude the following two files when clearing the `files` folder: `godot-bootstrap-dex.jar` and `main-dex.jar`.
6875

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/GodotExtension.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ open class GodotExtension(objects: ObjectFactory) {
2626
*/
2727
var androidCompileSdkDir = objects.fileProperty()
2828

29+
/**
30+
* Min android api version.
31+
*
32+
* example: 21
33+
*/
34+
var androidMinApi = objects.property(Int::class.java)
35+
2936
/**
3037
* enable Graal Native Image Export
3138
*
@@ -88,6 +95,8 @@ open class GodotExtension(objects: ObjectFactory) {
8895
androidCompileSdkDir.set(androidCompileSdkDirFile)
8996
}
9097

98+
androidMinApi.set(21)
99+
91100
isGraalNativeImageExportEnabled.set(false)
92101
nativeImageToolPath.set(System.getenv("native-image")?.let { File(it) })
93102
additionalGraalJniConfigurationFiles.set(arrayOf())

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/android/createMainDexFileTask.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ fun Project.createMainDexFileTask(
4040
mainJar.absolutePath,
4141
"--lib",
4242
"${godotJvmExtension.androidCompileSdkDir.get().asFile.absolutePath}${File.separator}android.jar",
43+
"--min-api",
44+
godotJvmExtension.androidMinApi.get(),
4345
)
4446
} else {
4547
commandLine(
@@ -49,6 +51,8 @@ fun Project.createMainDexFileTask(
4951
"${godotJvmExtension.androidCompileSdkDir.get().asFile.absolutePath}/android.jar",
5052
"--classpath",
5153
godotBootstrapJar.absolutePath,
54+
"--min-api",
55+
godotJvmExtension.androidMinApi.get(),
5256
)
5357
}
5458
}

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/android/packageBootstrapDexJarTask.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ fun Project.packageBootstrapDexJarTask(
3636
"godot-bootstrap-dex.jar",
3737
"--lib",
3838
"${godotJvmExtension.androidCompileSdkDir.get().asFile.absolutePath}${File.separator}android.jar",
39+
"--min-api",
40+
godotJvmExtension.androidMinApi.get(),
3941
)
4042
} else {
4143
commandLine(
@@ -45,6 +47,8 @@ fun Project.packageBootstrapDexJarTask(
4547
"godot-bootstrap-dex.jar",
4648
"--lib",
4749
"${godotJvmExtension.androidCompileSdkDir.get().asFile.absolutePath}/android.jar",
50+
"--min-api",
51+
godotJvmExtension.androidMinApi.get(),
4852
)
4953
}
5054
}

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/android/packageMainDexJarTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun Project.packageMainDexJarTask(
1717
archiveBaseName.set("main-dex")
1818

1919
from("src/main/resources").include("**/godot.runtime.Entry")
20-
from("${project.buildDir.absolutePath}/libs/").include("classes.dex")
20+
from("${project.buildDir.absolutePath}/libs/").include("*.dex")
2121

2222
dependsOn(createMainDexFileTask)
2323
}

0 commit comments

Comments
 (0)