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