mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
123 lines
4.0 KiB
Kotlin
123 lines
4.0 KiB
Kotlin
import org.gradle.api.GradleException
|
|
import org.gradle.api.tasks.Sync
|
|
|
|
plugins {
|
|
id("com.android.application")
|
|
}
|
|
|
|
val minAndroidJavaVersion = 17
|
|
val maxAndroidJavaVersion = 21
|
|
val hostJavaMajorVersion = JavaVersion.current().majorVersion.toIntOrNull()
|
|
?: throw GradleException("Unable to determine Java version from ${JavaVersion.current()}.")
|
|
if (hostJavaMajorVersion < minAndroidJavaVersion) {
|
|
throw GradleException(
|
|
"Android Genie build requires Java ${minAndroidJavaVersion}+ (tested through Java ${maxAndroidJavaVersion}). Found Java ${hostJavaMajorVersion}."
|
|
)
|
|
}
|
|
val androidJavaTargetVersion = hostJavaMajorVersion.coerceAtMost(maxAndroidJavaVersion)
|
|
val androidJavaVersion = JavaVersion.toVersion(androidJavaTargetVersion)
|
|
val agentPlatformStubSdkZip = providers
|
|
.gradleProperty("agentPlatformStubSdkZip")
|
|
.orElse(providers.environmentVariable("ANDROID_AGENT_PLATFORM_STUB_SDK_ZIP"))
|
|
val skipAndroidLto = providers
|
|
.gradleProperty("codexAndroidSkipLto")
|
|
.orElse(providers.environmentVariable("CODEX_ANDROID_SKIP_LTO"))
|
|
.orNull
|
|
?.let { it == "1" || it.equals("true", ignoreCase = true) }
|
|
?: false
|
|
val codexCargoProfileDir = if (skipAndroidLto) "android-release-no-lto" else "release"
|
|
val extractedAgentPlatformJar = layout.buildDirectory.file(
|
|
"generated/agent-platform/android-agent-platform-stub-sdk.jar"
|
|
)
|
|
val repoRoot = rootProject.projectDir.parentFile
|
|
val codexTargets = mapOf(
|
|
"arm64-v8a" to "aarch64-linux-android",
|
|
"x86_64" to "x86_64-linux-android",
|
|
)
|
|
val codexJniDir = layout.buildDirectory.dir("generated/codex-jni")
|
|
|
|
android {
|
|
namespace = "com.openai.codex.genie"
|
|
compileSdk = 34
|
|
|
|
defaultConfig {
|
|
applicationId = "com.openai.codex.genie"
|
|
minSdk = 26
|
|
targetSdk = 34
|
|
versionCode = 1
|
|
versionName = "0.1.0"
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
isMinifyEnabled = false
|
|
proguardFiles(
|
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
"proguard-rules.pro",
|
|
)
|
|
}
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility = androidJavaVersion
|
|
targetCompatibility = androidJavaVersion
|
|
}
|
|
|
|
packaging {
|
|
jniLibs.useLegacyPackaging = true
|
|
}
|
|
}
|
|
|
|
val extractAgentPlatformStubSdk = tasks.register<Sync>("extractAgentPlatformStubSdk") {
|
|
val sdkZip = agentPlatformStubSdkZip.orNull
|
|
?: throw GradleException(
|
|
"Set ANDROID_AGENT_PLATFORM_STUB_SDK_ZIP or -PagentPlatformStubSdkZip to the Android Agent Platform stub SDK zip."
|
|
)
|
|
val outputDir = extractedAgentPlatformJar.get().asFile.parentFile
|
|
from(zipTree(sdkZip)) {
|
|
include("payloads/compile_only/android-agent-platform-stub-sdk.jar")
|
|
eachFile { path = name }
|
|
includeEmptyDirs = false
|
|
}
|
|
into(outputDir)
|
|
}
|
|
|
|
val syncCodexCliJniLibs = tasks.register<Sync>("syncCodexCliJniLibs") {
|
|
val outputDir = codexJniDir
|
|
into(outputDir)
|
|
dependsOn(rootProject.tasks.named("buildCodexCliNative"))
|
|
|
|
codexTargets.forEach { (abi, triple) ->
|
|
val binary = file("${repoRoot}/codex-rs/target/android/${triple}/${codexCargoProfileDir}/codex")
|
|
from(binary) {
|
|
into(abi)
|
|
rename { "libcodex.so" }
|
|
}
|
|
}
|
|
|
|
doFirst {
|
|
codexTargets.forEach { (abi, triple) ->
|
|
val binary = file("${repoRoot}/codex-rs/target/android/${triple}/${codexCargoProfileDir}/codex")
|
|
if (!binary.exists()) {
|
|
throw GradleException(
|
|
"Missing codex binary for ${abi} at ${binary}. The Gradle native build task should have produced it."
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
android.sourceSets["main"].jniLibs.srcDir(codexJniDir.get().asFile)
|
|
|
|
tasks.named("preBuild").configure {
|
|
dependsOn(extractAgentPlatformStubSdk)
|
|
dependsOn(syncCodexCliJniLibs)
|
|
}
|
|
|
|
dependencies {
|
|
implementation(project(":bridge"))
|
|
compileOnly(files(extractedAgentPlatformJar))
|
|
testImplementation("junit:junit:4.13.2")
|
|
testImplementation("org.json:json:20240303")
|
|
}
|