mirror of https://github.com/auygun/kaliber.git
Use productFlavors
This commit is contained in:
parent
10d411bafd
commit
37afc006d2
17
README.md
17
README.md
|
@ -26,25 +26,24 @@ Build all games in release mode and run "hello_world".
|
|||
ninja -C out/release
|
||||
./out/release/hello_world
|
||||
```
|
||||
Build only "demo" in debug mode and run.
|
||||
Build "demo" in debug mode and run.
|
||||
```text
|
||||
ninja -C out/debug demo
|
||||
./out/debug/demo
|
||||
```
|
||||
|
||||
### Android:
|
||||
Build the default game ("hello_world") in debug mode for all ABIs and install.
|
||||
GN will be run by Gradle so no setup is required.
|
||||
Build "hello_world" in debug mode for all ABIs and install. GN will be run by
|
||||
Gradle so no setup is required.
|
||||
```text
|
||||
cd build/android
|
||||
./gradlew :app:installDebug
|
||||
./gradlew :app:installHelloWorldDebug
|
||||
```
|
||||
Build configuration can be changed via project properties. The following command
|
||||
will build "demo" in debug mode for x86_64 ABI and install. "targetArchs"
|
||||
property can be set to any combination of Arm7, Arm8, X86_64, X86. Location of
|
||||
gn and ninja executables can also be specified via "gn" and "ninja" properties.
|
||||
Build "demo" in debug mode for x86_64 ABI and install. "targetArchs" can be set
|
||||
to any combination of Arm7, Arm8, X86_64, X86. Location of gn and ninja
|
||||
executables can also be specified via "gn" and "ninja" properties.
|
||||
```text
|
||||
./gradlew :app:installDebug -PtargetArchs="X86_64" -PtargetGame="demo"
|
||||
./gradlew :app:installDemoDebug -PtargetArchs="X86_64"
|
||||
```
|
||||
|
||||
### Generate Visual Studio solution:
|
||||
|
|
|
@ -41,16 +41,18 @@ class Utils implements Plugin<Project> {
|
|||
}
|
||||
|
||||
void addTask(String prefix, Closure taskClosure) {
|
||||
forEachBuildVariant { String arch, String buildType ->
|
||||
def taskName = "${prefix}${arch}${buildType}"
|
||||
taskClosure(taskName, buildType, arch)
|
||||
forEachBuildVariant { String game, String arch, String buildType ->
|
||||
def taskName = "${prefix}${game}${arch}${buildType}"
|
||||
taskClosure(taskName, buildType, arch, game)
|
||||
}
|
||||
}
|
||||
|
||||
void forEachBuildVariant(Closure callback) {
|
||||
project.rootProject.ext.targetArchs.each { arch ->
|
||||
BUILD_TYPES.each { buildType ->
|
||||
callback(arch, buildType)
|
||||
project.android.productFlavors.each { flavor ->
|
||||
project.rootProject.ext.targetArchs.each { arch ->
|
||||
BUILD_TYPES.each { buildType ->
|
||||
callback(flavor.name.capitalize(), arch, buildType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +79,17 @@ def getJniLibsDir(String buildType) {
|
|||
return "${project.buildDir}/gn_out/jniLibs/${buildType.toLowerCase()}"
|
||||
}
|
||||
|
||||
def getGnTargetFor(String game) {
|
||||
def outStr = ''
|
||||
android.productFlavors.find { flavor ->
|
||||
if (flavor.name.capitalize() == game) {
|
||||
outStr = flavor.ext.gnTarget
|
||||
return true
|
||||
}
|
||||
}
|
||||
return outStr
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: Utils
|
||||
|
||||
|
@ -100,6 +113,7 @@ android {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
|
@ -107,6 +121,24 @@ android {
|
|||
'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions 'game'
|
||||
|
||||
productFlavors {
|
||||
helloWorld {
|
||||
dimension 'game'
|
||||
ext {
|
||||
gnTarget = "hello_world"
|
||||
}
|
||||
}
|
||||
demo {
|
||||
dimension 'game'
|
||||
ext {
|
||||
gnTarget = "demo"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += ['../../../src/engine/platform/java/com/kaliber/base']
|
||||
|
@ -122,6 +154,7 @@ android {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace rootProject.ext.applicationId
|
||||
}
|
||||
|
||||
|
@ -132,16 +165,16 @@ dependencies {
|
|||
implementation 'com.google.android.gms:play-services-ads:22.0.0'
|
||||
}
|
||||
|
||||
utils.addTask('generateGnArgsFor') { String taskName, String buildType, String arch ->
|
||||
utils.addTask('generateGnArgsFor') { String taskName, String buildType, String arch, String game ->
|
||||
task(taskName, type: WriteFileTask) {
|
||||
content = generateGnArgsContent(buildType, arch)
|
||||
target = project.layout.file(provider { new File("${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", 'args.gn') })
|
||||
}
|
||||
}
|
||||
|
||||
utils.addTask('runGnFor') { String taskName, String buildType, String arch ->
|
||||
utils.addTask('runGnFor') { String taskName, String buildType, String arch, String game ->
|
||||
task(taskName, type: Exec) {
|
||||
dependsOn "generateGnArgsFor${arch}${buildType}"
|
||||
dependsOn "generateGnArgsFor${game}${arch}${buildType}"
|
||||
|
||||
executable rootProject.ext.gn
|
||||
args '--fail-on-unused-args', 'gen', "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}"
|
||||
|
@ -151,58 +184,58 @@ utils.addTask('runGnFor') { String taskName, String buildType, String arch ->
|
|||
}
|
||||
}
|
||||
|
||||
utils.addTask('runNinjaFor') { String taskName, String buildType, String arch ->
|
||||
utils.addTask('runNinjaFor') { String taskName, String buildType, String arch, String game ->
|
||||
task(taskName, type: Exec) {
|
||||
dependsOn "runGnFor${arch}${buildType}"
|
||||
dependsOn "runGnFor${game}${arch}${buildType}"
|
||||
|
||||
executable rootProject.ext.ninja
|
||||
args '-C', "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", rootProject.ext.targetGame
|
||||
args '-C', "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", getGnTargetFor(game)
|
||||
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
}
|
||||
|
||||
utils.addTask('copyAssetsFor') { String taskName, String buildType, String arch ->
|
||||
utils.addTask('copyAssetsFor') { String taskName, String buildType, String arch, String game ->
|
||||
task(taskName, type: Copy) {
|
||||
dependsOn "runNinjaFor${arch}${buildType}"
|
||||
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
||||
|
||||
from "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}/assets"
|
||||
into getAssetsDir(buildType)
|
||||
}
|
||||
}
|
||||
|
||||
utils.addTask('copyJniLibsFor') { String taskName, String buildType, String arch ->
|
||||
utils.addTask('copyJniLibsFor') { String taskName, String buildType, String arch, String game ->
|
||||
task(taskName, type: Copy) {
|
||||
dependsOn "runNinjaFor${arch}${buildType}"
|
||||
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
||||
|
||||
from("${getOutDir(buildType)}/${utils.ABI_CODES[arch]}") {
|
||||
include "lib${rootProject.ext.targetGame}.so"
|
||||
rename "lib${rootProject.ext.targetGame}.so", "libkaliber.so"
|
||||
include "lib${getGnTargetFor(game)}.so"
|
||||
rename "lib${getGnTargetFor(game)}.so", "libkaliber.so"
|
||||
}
|
||||
into "${getJniLibsDir(buildType)}/${utils.ABI_CODES[arch]}"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.configureEach { task ->
|
||||
def match = task.name =~ /^merge(${utils.BUILD_TYPES_REG_EXP})JniLibFolders$/
|
||||
def match = task.name =~ /^merge(\w+)(${utils.BUILD_TYPES_REG_EXP})JniLibFolders$/
|
||||
if (match) {
|
||||
rootProject.ext.targetArchs.each { arch ->
|
||||
task.dependsOn "copyJniLibsFor${arch}${match.group(1)}"
|
||||
return
|
||||
task.dependsOn "copyJniLibsFor${match.group(1)}${arch}${match.group(2)}"
|
||||
}
|
||||
return
|
||||
}
|
||||
match = task.name =~ /^merge(${utils.BUILD_TYPES_REG_EXP})Assets$/
|
||||
match = task.name =~ /^merge(\w+)(${utils.BUILD_TYPES_REG_EXP})Assets$/
|
||||
if (match) {
|
||||
rootProject.ext.targetArchs.each { arch ->
|
||||
task.dependsOn "copyAssetsFor${arch}${match.group(1)}"
|
||||
return
|
||||
task.dependsOn "copyAssetsFor${match.group(1)}${arch}${match.group(2)}"
|
||||
}
|
||||
return
|
||||
}
|
||||
match = task.name =~ /^lintVitalAnalyze(${utils.BUILD_TYPES_REG_EXP})$/
|
||||
match = task.name =~ /^lintVitalAnalyze(\w+)(${utils.BUILD_TYPES_REG_EXP})$/
|
||||
if (match) {
|
||||
rootProject.ext.targetArchs.each { arch ->
|
||||
task.dependsOn "copyAssetsFor${arch}${match.group(1)}"
|
||||
return
|
||||
task.dependsOn "copyAssetsFor${match.group(1)}${arch}${match.group(2)}"
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,6 @@ task clean(type: Delete) {
|
|||
}
|
||||
|
||||
ext {
|
||||
if (!project.hasProperty('targetGame')) {
|
||||
targetGame = "hello_world"
|
||||
}
|
||||
|
||||
if (!project.hasProperty('targetArchs')) {
|
||||
targetArchs = ['Arm7', 'Arm8', 'X86_64', 'X86']
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue