Get ABI codes from productFlavors and remove hard-coded strings

This commit is contained in:
Attila Uygun 2023-09-05 19:06:53 +02:00
parent 05252bfae8
commit 5f8f70ed53
2 changed files with 30 additions and 20 deletions

View File

@ -34,16 +34,16 @@ ninja -C out/debug demo
### Android: ### Android:
Build "hello_world" in debug mode for all ABIs and install. GN will be run by Build "hello_world" in debug mode for all ABIs and install. GN will be run by
Gradle so no setup is required. Gradle so no setup is required. Location of gn and ninja executables can be
specified via "gn" and "ninja" properties (-Pgn="path/gn").
```text ```text
cd build/android cd build/android
./gradlew :app:installHelloWorldDebug ./gradlew :app:installHelloWorldAllArchsDebug
``` ```
Build "demo" in debug mode for x86_64 ABI and install. "targetArchs" can be set Build "demo" in debug mode for x86_64 ABI and install. Valid ABI targets are
to any combination of Arm7, Arm8, X86_64, X86. Location of gn and ninja Arm, Arm64, X86, X64, AllArchs, ArmOnly, X86Only.
executables can also be specified via "gn" and "ninja" properties.
```text ```text
./gradlew :app:installDemoDebug -PtargetArchs="X86_64" ./gradlew :app:installDemoX64Debug
``` ```
### Generate Visual Studio solution: ### Generate Visual Studio solution:

View File

@ -17,10 +17,6 @@ abstract class WriteFileTask extends DefaultTask {
} }
class Utils implements Plugin<Project> { class Utils implements Plugin<Project> {
final def ABI_CODES = ["Arm": "armeabi-v7a",
"Arm64": "arm64-v8a",
"X64": "x86_64",
"X86": "x86"].asImmutable()
final def ARCH_CODES = ["armeabi-v7a": "Arm", final def ARCH_CODES = ["armeabi-v7a": "Arm",
"arm64-v8a": "Arm64", "arm64-v8a": "Arm64",
"x86_64": "X64", "x86_64": "X64",
@ -83,6 +79,17 @@ class Utils implements Plugin<Project> {
return outList return outList
} }
def getAbiCodeFor(String arch) {
def outStr = ''
project.android.productFlavors.find { flavor ->
if (flavor.name.capitalize() == arch) {
outStr = flavor.ndk.abiFilters.first()
return true
}
}
return outStr
}
def getGnTargetFor(String game) { def getGnTargetFor(String game) {
def outStr = '' def outStr = ''
project.android.productFlavors.find { flavor -> project.android.productFlavors.find { flavor ->
@ -282,7 +289,7 @@ utils.addTask('copyJniLibsFor') { String taskName, String buildType, String arch
include "lib${utils.getGnTargetFor(game)}.so" include "lib${utils.getGnTargetFor(game)}.so"
rename "lib${utils.getGnTargetFor(game)}.so", "libkaliber.so" rename "lib${utils.getGnTargetFor(game)}.so", "libkaliber.so"
} }
into "${utils.getJniLibsDir(buildType)}/${utils.ABI_CODES[arch]}" into "${utils.getJniLibsDir(buildType)}/${utils.getAbiCodeFor(arch)}"
} }
} }
@ -291,9 +298,10 @@ tasks.configureEach { task ->
def match = task.name =~ /^merge/ + variantPattern + /JniLibFolders$/ def match = task.name =~ /^merge/ + variantPattern + /JniLibFolders$/
if (match) { if (match) {
android.productFlavors.find { flavor -> android.productFlavors.find { arch ->
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) { if (arch.dimension == 'arch' && arch.name.capitalize() == match.group(2)) {
flavor.ndk.abiFilters.each { abi -> // Depends on each arch type for multi-arch build flavors.
arch.ndk.abiFilters.each { abi ->
task.dependsOn "copyJniLibsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}" task.dependsOn "copyJniLibsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
} }
return true return true
@ -303,9 +311,10 @@ tasks.configureEach { task ->
} }
match = task.name =~ /^merge/ + variantPattern + /Assets$/ match = task.name =~ /^merge/ + variantPattern + /Assets$/
if (match) { if (match) {
android.productFlavors.find { flavor -> android.productFlavors.find { arch ->
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) { if (arch.dimension == 'arch' && arch.name.capitalize() == match.group(2)) {
flavor.ndk.abiFilters.each { abi -> // Depends on each arch type for multi-arch build flavors.
arch.ndk.abiFilters.each { abi ->
task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}" task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
} }
return true return true
@ -315,9 +324,10 @@ tasks.configureEach { task ->
} }
match = task.name =~ /^lintVitalAnalyze/ + variantPattern + /$/ match = task.name =~ /^lintVitalAnalyze/ + variantPattern + /$/
if (match) { if (match) {
android.productFlavors.find { flavor -> android.productFlavors.find { arch ->
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) { if (arch.dimension == 'arch' && arch.name.capitalize() == match.group(2)) {
flavor.ndk.abiFilters.each { abi -> // Depends on each arch type for multi-arch build flavors.
arch.ndk.abiFilters.each { abi ->
task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}" task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
} }
return true return true