Files
baji-vc/app/build.gradle
T

127 lines
7.0 KiB
Groovy

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.compose'
}
// Populated once by scripts/prepare-expression.sh from stable Maven versions, then pinned.
def expressionVersions = new Properties()
def expressionVersionFile = rootProject.file('gradle/expression-versions.properties')
if (!expressionVersionFile.isFile()) {
throw new GradleException('Run ./scripts/prepare-expression.sh in the external shell before building M5')
}
expressionVersionFile.withInputStream { expressionVersions.load(it) }
def cameraVersion = expressionVersions.getProperty('camerax.version')
def mediaPipeVersion = expressionVersions.getProperty('mediapipe.version')
def avatarEngineering = providers.gradleProperty('avatarEngineering').orNull == 'true'
def avatarNatural = providers.gradleProperty('avatarNatural').orNull == 'true'
def avatarUiCandidate = providers.gradleProperty('avatarUiCandidate').orNull == 'true'
def avatarMouthCandidate = providers.gradleProperty('avatarMouthCandidate').orNull == 'true'
def avatarActionCandidate = providers.gradleProperty('avatarActionCandidate').orNull == 'true'
def actionVersionCode = (providers.gradleProperty('actionVersionCode').orNull ?: '16').toInteger()
if (avatarActionCandidate && (!avatarMouthCandidate || actionVersionCode < 16)) {
throw new GradleException('Action stage requires the existing mouth runtime and a fresh code >=16')
}
if (avatarMouthCandidate && (!avatarNatural || avatarUiCandidate)) {
throw new GradleException('Mouth candidate requires natural runtime and a distinct version from UI-only')
}
if (avatarUiCandidate && !avatarNatural) {
throw new GradleException('UI candidate requires the pinned natural debug runtime')
}
def naturalManifestSha = providers.gradleProperty('naturalManifestSha').orNull ?: ''
def emotionManifestSha = providers.gradleProperty('emotionManifestSha').orNull ?: ''
if (emotionManifestSha && !(emotionManifestSha ==~ /[0-9a-f]{64}/)) throw new GradleException('Emotion graph requires exact external manifest SHA')
if (avatarNatural && !(naturalManifestSha ==~ /[0-9a-f]{64}/)) {
throw new GradleException('Natural debug candidate requires exact runtime manifest SHA')
}
if (!cameraVersion || !mediaPipeVersion) {
throw new GradleException('Incomplete gradle/expression-versions.properties; run scripts/prepare-expression.sh')
}
// Android's <domain> text cannot reference @string. Generate it from the one address config
// so changing voice_server_host and rebuilding also updates the certificate trust scope.
def networkSecurityResources = layout.buildDirectory.dir('generated/networkSecurity/res')
def generateNetworkSecurityConfig = tasks.register('generateNetworkSecurityConfig') {
def serverConfig = file('src/main/res/values/config.xml')
def template = file('src/main/network_security_config.xml')
inputs.files(serverConfig, template)
outputs.dir(networkSecurityResources)
doLast {
def host = new XmlSlurper().parse(serverConfig).string.find {
it.@name.text() == 'voice_server_host'
}.text()
if (!(host ==~ /[A-Za-z0-9.:-]+/)) {
throw new GradleException('voice_server_host must be an IP address or DNS host')
}
def output = new File(networkSecurityResources.get().asFile, 'xml/network_security_config.xml')
output.parentFile.mkdirs()
output.setText(template.getText('UTF-8').replace('@VOICE_SERVER_HOST@', host), 'UTF-8')
}
}
// AndroidSourceDirectorySet excludes do not reliably filter mergeAssets. A Sync
// staging directory applies actual file exclusions without touching archived imports.
def packagedAssets = layout.buildDirectory.dir('generated/packagedAssets')
def stagePackagedAssets = tasks.register('stagePackagedAssets', Sync) {
from('src/main/assets')
exclude 'avatar/a01-v1/**', 'avatar/a01-standing-v2/**'
if (!avatarMouthCandidate) exclude 'avatar/a01-neutral-graph-v1/runtime-04/**'
into(packagedAssets)
}
android {
namespace 'com.gorios.lanvoice'
compileSdk 34
defaultConfig {
applicationId 'com.gorios.lanvoice'
minSdk 26
targetSdk 34
testInstrumentationRunner 'com.gorios.lanvoice.AvatarCleanUiInstrumentation'
versionCode avatarActionCandidate ? actionVersionCode : (avatarMouthCandidate ? 15 : (avatarUiCandidate ? 14 : (avatarNatural ? 13 : 12)))
versionName = avatarActionCandidate ? '0.7.0' : ((avatarUiCandidate || avatarMouthCandidate) ? '0.6.2' : '0.6.1')
ndk { abiFilters 'arm64-v8a' }
}
compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }
kotlinOptions { jvmTarget = '17' }
buildFeatures { compose true; buildConfig true }
buildTypes {
debug {
if (avatarActionCandidate) versionNameSuffix '-stage-dev'
else if (avatarMouthCandidate) versionNameSuffix '-mouth-dev'
else if (avatarUiCandidate) versionNameSuffix '-ui-dev'
else if (avatarNatural) versionNameSuffix '-natural-dev'
else if (avatarEngineering) versionNameSuffix '-dev'
buildConfigField 'boolean', 'AVATAR_ENGINEERING', (avatarEngineering || avatarNatural) ? 'true' : 'false'
buildConfigField 'boolean', 'AVATAR_NATURAL', avatarNatural ? 'true' : 'false'
buildConfigField 'boolean', 'AVATAR_MOUTH_CANDIDATE', avatarMouthCandidate ? 'true' : 'false'
buildConfigField 'String', 'NATURAL_MANIFEST_SHA', '"' + (avatarNatural ? naturalManifestSha : '') + '"'
buildConfigField 'String', 'EMOTION_MANIFEST_SHA', '"' + emotionManifestSha + '"'
}
release {
buildConfigField 'boolean', 'AVATAR_ENGINEERING', 'false'
buildConfigField 'boolean', 'AVATAR_NATURAL', 'false'
buildConfigField 'boolean', 'AVATAR_MOUTH_CANDIDATE', 'false'
buildConfigField 'String', 'NATURAL_MANIFEST_SHA', '""'
buildConfigField 'String', 'EMOTION_MANIFEST_SHA', '""'
}
}
androidResources { noCompress += ['task', 'mp4'] }
sourceSets.main.res.srcDir(networkSecurityResources)
// Retain private archived imports on disk, but never put old seated/arms-down
// animation packs into the new graph APK.
sourceSets.main.assets.setSrcDirs([packagedAssets])
}
tasks.named('preBuild').configure { dependsOn(generateNetworkSecurityConfig, stagePackagedAssets) }
dependencies {
implementation platform('androidx.compose:compose-bom:2024.09.03')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.material3:material3'
implementation 'androidx.activity:activity-compose:1.9.3'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation "com.google.mediapipe:tasks-vision:$mediaPipeVersion"
implementation "androidx.camera:camera-core:$cameraVersion"
implementation "androidx.camera:camera-camera2:$cameraVersion"
implementation "androidx.camera:camera-lifecycle:$cameraVersion"
implementation "androidx.camera:camera-view:$cameraVersion"
}