Skip to content

Commit

Permalink
Dev: add API level property
Browse files Browse the repository at this point in the history
  • Loading branch information
andriydruk committed Oct 25, 2023
1 parent d3ca78b commit 3db1470
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ext {
// Provide your own coordinates here
PUBLISH_GROUP_ID = 'com.readdle.android.swift'
PUBLISH_ARTIFACT_ID = 'gradle'
PUBLISH_VERSION = '1.4.4'
PUBLISH_VERSION = '1.4.5'
}

apply from: "${rootProject.projectDir}/publish-module.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ class SwiftAndroidPlugin implements Plugin<Project> {

def configurationArgs = ["--configuration", isDebug ? "debug" : "release"]
def extraArgs = isDebug ? extension.debug.extraInstallFlags : extension.release.extraInstallFlags
def apiLevel = extension.apiLevel

return project.task(type: Exec, "swiftInstall${variantName}") {
workingDir "src/main/swift"
executable toolchainHandle.swiftInstallPath
args configurationArgs + extraArgs
environment toolchainHandle.swiftEnv
environment toolchainHandle.getSwiftEnv(apiLevel)
}
}

Expand All @@ -214,12 +215,13 @@ class SwiftAndroidPlugin implements Plugin<Project> {
def configurationArgs = ["--configuration", isDebug ? "debug" : "release"]
def extraArgs = isDebug ? extension.debug.extraBuildFlags : extension.release.extraBuildFlags
def arguments = configurationArgs + extraArgs
def apiLevel = extension.apiLevel

return project.task(type: Exec, "swiftBuild${taskQualifier}") {
workingDir "src/main/swift"
executable toolchainHandle.swiftBuildPath
args arguments
environment toolchainHandle.getFullEnv(arch)
environment toolchainHandle.getFullEnv(arch, apiLevel)

doFirst {
checkNdk()
Expand All @@ -232,6 +234,7 @@ class SwiftAndroidPlugin implements Plugin<Project> {

private Task createCopyTask(Project project, BaseVariant variant, Arch arch, Task swiftBuildTask) {
def taskQualifier = taskQualifier(variant, arch)
def extension = project.extensions.getByType(SwiftAndroidPluginExtension)

def task = project.tasks.findByName("copySwift${taskQualifier}")
if (task != null) {
Expand All @@ -240,8 +243,8 @@ class SwiftAndroidPlugin implements Plugin<Project> {

boolean isDebug = variant.buildType.isJniDebuggable()
String swiftPmBuildPath = isDebug
? "src/main/swift/.build/${arch.swiftTriple}/debug"
: "src/main/swift/.build/${arch.swiftTriple}/release"
? "src/main/swift/.build/${arch.swiftTriple}${extension.apiLevel}/debug"
: "src/main/swift/.build/${arch.swiftTriple}${extension.apiLevel}/release"

def outputLibraries = project.fileTree(swiftPmBuildPath) {
include "*.so", "*.so.*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SwiftAndroidPluginExtension {
boolean usePackageClean = true
boolean swiftLintEnabled = false
boolean useKapt = false
int apiLevel = 24

SwiftAndroidPluginExtension(Project project) {
this.project = project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ class ToolchainHandle {
return getFolderInToolchain("usr/lib/swift-${arch.swiftArch}/android")
}

Map<String, String> getSwiftEnv() {
Map<String, String> getSwiftEnv(int apiLevel) {
return [
SWIFT_ANDROID_HOME: toolchainFolder?.absolutePath,
SWIFT_ANDROID_API_LEVEL: apiLevel.toString()
]
}

Map<String, String> getFullEnv(Arch arch) {
Map<String, String> getFullEnv(Arch arch, int apiLevel) {
return [
SWIFT_ANDROID_ARCH: arch.swiftArch,
SWIFT_ANDROID_HOME: toolchainFolder?.absolutePath,
SWIFT_ANDROID_API_LEVEL: apiLevel.toString(),
ANDROID_NDK_HOME: ndkFolder?.absolutePath
]
}
Expand Down

0 comments on commit 3db1470

Please sign in to comment.