mirror of https://github.com/auygun/kaliber.git
Add archs to productFlavors
This commit is contained in:
parent
e6d89add57
commit
01bffc71ac
|
@ -18,12 +18,17 @@ abstract class WriteFileTask extends DefaultTask {
|
||||||
|
|
||||||
class Utils implements Plugin<Project> {
|
class Utils implements Plugin<Project> {
|
||||||
final def BUILD_TYPES = ['Debug', 'Release'].asImmutable()
|
final def BUILD_TYPES = ['Debug', 'Release'].asImmutable()
|
||||||
|
final def ARCH_TYPES = ['Arm7', 'Arm8', 'X86_64', 'X86']
|
||||||
final def BUILD_TYPES_REG_EXP = BUILD_TYPES.join('|')
|
final def BUILD_TYPES_REG_EXP = BUILD_TYPES.join('|')
|
||||||
|
|
||||||
final def ABI_CODES = ["Arm7": "armeabi-v7a",
|
final def ABI_CODES = ["Arm7": "armeabi-v7a",
|
||||||
"Arm8": "arm64-v8a",
|
"Arm8": "arm64-v8a",
|
||||||
"X86_64": "x86_64",
|
"X86_64": "x86_64",
|
||||||
"X86": "x86"].asImmutable()
|
"X86": "x86"].asImmutable()
|
||||||
|
final def ARCH_CODES = ["armeabi-v7a": "Arm7",
|
||||||
|
"arm64-v8a": "Arm8",
|
||||||
|
"x86_64": "X86_64",
|
||||||
|
"x86": "X86"].asImmutable()
|
||||||
final def CPU_CODES = ["Arm7": "arm",
|
final def CPU_CODES = ["Arm7": "arm",
|
||||||
"Arm8": "arm64",
|
"Arm8": "arm64",
|
||||||
"X86_64": "x64",
|
"X86_64": "x64",
|
||||||
|
@ -49,7 +54,8 @@ class Utils implements Plugin<Project> {
|
||||||
|
|
||||||
void forEachBuildVariant(Closure callback) {
|
void forEachBuildVariant(Closure callback) {
|
||||||
project.android.productFlavors.each { flavor ->
|
project.android.productFlavors.each { flavor ->
|
||||||
project.rootProject.ext.targetArchs.each { arch ->
|
if (flavor.dimension == 'game') {
|
||||||
|
ARCH_TYPES.each { arch ->
|
||||||
BUILD_TYPES.each { buildType ->
|
BUILD_TYPES.each { buildType ->
|
||||||
callback(flavor.name.capitalize(), arch, buildType)
|
callback(flavor.name.capitalize(), arch, buildType)
|
||||||
}
|
}
|
||||||
|
@ -57,6 +63,7 @@ class Utils implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def generateGnArgsContent(String buildType, String arch) {
|
def generateGnArgsContent(String buildType, String arch) {
|
||||||
def content = 'target_os="android"\n'
|
def content = 'target_os="android"\n'
|
||||||
|
@ -82,7 +89,7 @@ def getJniLibsDir(String buildType) {
|
||||||
def getGnTargetFor(String game) {
|
def getGnTargetFor(String game) {
|
||||||
def outStr = ''
|
def outStr = ''
|
||||||
android.productFlavors.find { flavor ->
|
android.productFlavors.find { flavor ->
|
||||||
if (flavor.name.capitalize() == game) {
|
if (flavor.dimension == 'game' && flavor.name.capitalize() == game) {
|
||||||
outStr = flavor.ext.gnTarget
|
outStr = flavor.ext.gnTarget
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -90,14 +97,19 @@ def getGnTargetFor(String game) {
|
||||||
return outStr
|
return outStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getArchTypesRegExp() {
|
||||||
|
def outList = []
|
||||||
|
android.productFlavors.each { flavor ->
|
||||||
|
if (flavor.dimension == 'arch') {
|
||||||
|
outList += flavor.name.capitalize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outList
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: Utils
|
apply plugin: Utils
|
||||||
|
|
||||||
rootProject.ext.targetArchs.each { arch ->
|
|
||||||
assert utils.ABI_CODES.containsKey(arch)
|
|
||||||
assert utils.CPU_CODES.containsKey(arch)
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdk rootProject.ext.compileSdk
|
compileSdk rootProject.ext.compileSdk
|
||||||
ndkVersion rootProject.ext.ndkVersion
|
ndkVersion rootProject.ext.ndkVersion
|
||||||
|
@ -107,9 +119,6 @@ android {
|
||||||
targetSdk rootProject.ext.targetSdk
|
targetSdk rootProject.ext.targetSdk
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters = []
|
abiFilters = []
|
||||||
rootProject.ext.targetArchs.each { arch ->
|
|
||||||
abiFilters.add(utils.ABI_CODES[arch])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +130,7 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flavorDimensions 'game'
|
flavorDimensions 'game', 'arch'
|
||||||
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
helloWorld {
|
helloWorld {
|
||||||
|
@ -144,6 +153,49 @@ android {
|
||||||
gnTarget = "demo"
|
gnTarget = "demo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arm7 {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["armeabi-v7a"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arm8 {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["arm64-v8a"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x86 {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["x86"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x86_64 {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["x86_64"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allArchs {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["armeabi-v7a", "arm64-v8a", "x86_64", "x86"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
armOnly {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["armeabi-v7a", "arm64-v8a"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x86Only {
|
||||||
|
dimension 'arch'
|
||||||
|
ndk {
|
||||||
|
abiFilters = ["x86_64", "x86"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
@ -175,7 +227,7 @@ dependencies {
|
||||||
utils.addTask('generateGnArgsFor') { String taskName, String buildType, String arch, String game ->
|
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)}/${arch}", 'args.gn') })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,10 +236,10 @@ utils.addTask('runGnFor') { String taskName, String buildType, String arch, Stri
|
||||||
dependsOn "generateGnArgsFor${game}${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)}/${arch}"
|
||||||
|
|
||||||
inputs.file(new File("${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", 'args.gn'))
|
inputs.file(new File("${getOutDir(buildType)}/${arch}", 'args.gn'))
|
||||||
outputs.file(new File("${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", 'build.ninja'))
|
outputs.file(new File("${getOutDir(buildType)}/${arch}", 'build.ninja'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +248,7 @@ utils.addTask('runNinjaFor') { String taskName, String buildType, String arch, S
|
||||||
dependsOn "runGnFor${game}${arch}${buildType}"
|
dependsOn "runGnFor${game}${arch}${buildType}"
|
||||||
|
|
||||||
executable rootProject.ext.ninja
|
executable rootProject.ext.ninja
|
||||||
args '-C', "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}", getGnTargetFor(game)
|
args '-C', "${getOutDir(buildType)}/${arch}", getGnTargetFor(game)
|
||||||
|
|
||||||
outputs.upToDateWhen { false }
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
@ -206,7 +258,7 @@ utils.addTask('copyAssetsFor') { String taskName, String buildType, String arch,
|
||||||
task(taskName, type: Copy) {
|
task(taskName, type: Copy) {
|
||||||
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
||||||
|
|
||||||
from "${getOutDir(buildType)}/${utils.ABI_CODES[arch]}/assets"
|
from "${getOutDir(buildType)}/${arch}/assets"
|
||||||
into getAssetsDir(buildType)
|
into getAssetsDir(buildType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +267,7 @@ utils.addTask('copyJniLibsFor') { String taskName, String buildType, String arch
|
||||||
task(taskName, type: Copy) {
|
task(taskName, type: Copy) {
|
||||||
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
dependsOn "runNinjaFor${game}${arch}${buildType}"
|
||||||
|
|
||||||
from("${getOutDir(buildType)}/${utils.ABI_CODES[arch]}") {
|
from("${getOutDir(buildType)}/${arch}") {
|
||||||
include "lib${getGnTargetFor(game)}.so"
|
include "lib${getGnTargetFor(game)}.so"
|
||||||
rename "lib${getGnTargetFor(game)}.so", "libkaliber.so"
|
rename "lib${getGnTargetFor(game)}.so", "libkaliber.so"
|
||||||
}
|
}
|
||||||
|
@ -224,24 +276,41 @@ utils.addTask('copyJniLibsFor') { String taskName, String buildType, String arch
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.configureEach { task ->
|
tasks.configureEach { task ->
|
||||||
def match = task.name =~ /^merge(\w+)(${utils.BUILD_TYPES_REG_EXP})JniLibFolders$/
|
def variantPattern = /(\w+)(${getArchTypesRegExp().join('|')})(${utils.BUILD_TYPES_REG_EXP})/
|
||||||
|
|
||||||
|
def match = task.name =~ /^merge/ + variantPattern + /JniLibFolders$/
|
||||||
if (match) {
|
if (match) {
|
||||||
rootProject.ext.targetArchs.each { arch ->
|
android.productFlavors.find { flavor ->
|
||||||
task.dependsOn "copyJniLibsFor${match.group(1)}${arch}${match.group(2)}"
|
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) {
|
||||||
|
flavor.ndk.abiFilters.each { abi ->
|
||||||
|
task.dependsOn "copyJniLibsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
match = task.name =~ /^merge(\w+)(${utils.BUILD_TYPES_REG_EXP})Assets$/
|
match = task.name =~ /^merge/ + variantPattern + /Assets$/
|
||||||
if (match) {
|
if (match) {
|
||||||
rootProject.ext.targetArchs.each { arch ->
|
android.productFlavors.find { flavor ->
|
||||||
task.dependsOn "copyAssetsFor${match.group(1)}${arch}${match.group(2)}"
|
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) {
|
||||||
|
flavor.ndk.abiFilters.each { abi ->
|
||||||
|
task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
match = task.name =~ /^lintVitalAnalyze(\w+)(${utils.BUILD_TYPES_REG_EXP})$/
|
match = task.name =~ /^lintVitalAnalyze/ + variantPattern + /$/
|
||||||
if (match) {
|
if (match) {
|
||||||
rootProject.ext.targetArchs.each { arch ->
|
android.productFlavors.find { flavor ->
|
||||||
task.dependsOn "copyAssetsFor${match.group(1)}${arch}${match.group(2)}"
|
if (flavor.dimension == 'arch' && flavor.name.capitalize() == match.group(2)) {
|
||||||
|
flavor.ndk.abiFilters.each { abi ->
|
||||||
|
task.dependsOn "copyAssetsFor${match.group(1)}${utils.ARCH_CODES[abi]}${match.group(3)}"
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,6 @@ ext {
|
||||||
compileSdk = 33
|
compileSdk = 33
|
||||||
targetSdk = 33
|
targetSdk = 33
|
||||||
|
|
||||||
if (!project.hasProperty('targetArchs')) {
|
|
||||||
targetArchs = ['Arm7', 'Arm8', 'X86_64', 'X86']
|
|
||||||
} else {
|
|
||||||
targetArchs = project.getProperty('targetArchs').split(',')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!project.hasProperty('gn')) {
|
if (!project.hasProperty('gn')) {
|
||||||
gn = "gn"
|
gn = "gn"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue