232 lines
20 KiB
Groovy
232 lines
20 KiB
Groovy
plugins {
|
|
id 'com.android.application'
|
|
id 'org.jetbrains.kotlin.android'
|
|
id 'org.jetbrains.kotlin.plugin.compose'
|
|
}
|
|
|
|
def characterProfileId = providers.gradleProperty('characterProfile').orNull ?: 'main'
|
|
def characterCatalogFile = rootProject.file('manifests/character-build-profiles.json')
|
|
def characterCatalog = new groovy.json.JsonSlurper().parse(characterCatalogFile)
|
|
def characterProfile = characterCatalog.profiles[characterProfileId]
|
|
if (!characterProfile || !(characterProfileId in ['main', 'lvbu-test', 'liam-test', 'liam-test-square540'])) throw new GradleException('Unknown trusted character profile')
|
|
def framingPresetId = providers.gradleProperty('avatarFramingPreset').orNull ?: (characterProfile.framingPreset ?: 'legacy')
|
|
if (framingPresetId != (characterProfile.framingPreset ?: 'legacy')) throw new GradleException('Profile/framing preset mismatch')
|
|
def framingPreset = framingPresetId == 'legacy' ? null : characterCatalog.framingPresets[framingPresetId]
|
|
if (framingPresetId != 'legacy' && (!framingPreset || framingPreset.profile != characterProfileId)) throw new GradleException('Unknown trusted framing preset')
|
|
if (characterProfileId != 'main') layout.buildDirectory.set(file('build/characters/' + characterProfileId + (framingPreset ? '/framing/' + framingPresetId : '')))
|
|
if (characterProfileId != 'main' && gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') }) throw new GradleException('Persona test profile is debug-only')
|
|
|
|
// 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 avatarUserNetworkActions = providers.gradleProperty('avatarUserNetworkActions').orNull == 'true'
|
|
def avatarUserAssetCandidate = providers.gradleProperty('avatarUserAssetCandidate').orNull == 'true'
|
|
def avatarStartupFix = providers.gradleProperty('avatarStartupFix').orNull == 'true'
|
|
def cameraCompatibilityFix = providers.gradleProperty('cameraCompatibilityFix').orNull == 'true'
|
|
def cameraDirectYuv = providers.gradleProperty('cameraDirectYuv').orNull == 'true'
|
|
def cameraProbeDiagnostic = providers.gradleProperty('cameraProbeDiagnostic').orNull == 'true'
|
|
def cameraPreviewStream = providers.gradleProperty('cameraPreviewStream').orNull == 'true'
|
|
def faceDiagnosticsFix = providers.gradleProperty('faceDiagnosticsFix').orNull == 'true'
|
|
def presenceCandidate = providers.gradleProperty('presenceCandidate').orNull == 'true'
|
|
def avatarPlaybackClockFix = providers.gradleProperty('avatarPlaybackClockFix').orNull == 'true'
|
|
def avatarPlaybackDiagnostic = providers.gradleProperty('avatarPlaybackDiagnostic').orNull == 'true'
|
|
def avatarRuntimeFix = providers.gradleProperty('avatarRuntimeFix').orNull == 'true'
|
|
def avatarFullActionCandidate = providers.gradleProperty('avatarFullActionCandidate').orNull == 'true'
|
|
def actionVersionCode = (providers.gradleProperty('actionVersionCode').orNull ?: '16').toInteger()
|
|
if (characterProfileId != 'main' && (!avatarUserAssetCandidate || actionVersionCode < characterProfile.minimumVersionCode)) throw new GradleException('Persona test requires authorized exact media and its minimum version code')
|
|
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 ?: ''
|
|
def characterMediaId = providers.gradleProperty('characterMediaBundle').orNull ?: (avatarUserAssetCandidate ? 'black-correct03' : 'white-full04')
|
|
def characterMedia = characterCatalog.mediaBundles[characterMediaId]
|
|
def allowedMedia = characterProfile.mediaSelection == 'existing-build-flags' ? ['black-correct03','white-full04'] : [characterProfile.mediaSelection] + (characterProfile.additionalMediaSelections ?: [])
|
|
if (!characterMedia || !(characterMediaId in allowedMedia)) throw new GradleException('Profile/media selection is not authorized')
|
|
if (avatarUserNetworkActions && characterMedia.networkActionsAllowed != true) throw new GradleException('Network dance requires separate reviewed media registration')
|
|
if (framingPreset && (framingPreset.mediaBundle != characterMediaId || framingPreset.indexSha256 != emotionManifestSha || !avatarUserAssetCandidate)) throw new GradleException('Framing preset requires exact authorized media')
|
|
if (framingPreset && (providers.gradleProperty('avatarFrameZoom').isPresent() || providers.gradleProperty('avatarFrameCenterY').isPresent())) throw new GradleException('Controlled preset cannot be overridden')
|
|
def avatarFrameZoom = (framingPreset ? framingPreset.zoom : (providers.gradleProperty('avatarFrameZoom').orNull ?: '1.0')).toFloat()
|
|
def avatarFrameCenterY = (framingPreset ? framingPreset.centerY : (providers.gradleProperty('avatarFrameCenterY').orNull ?: '0.5')).toFloat()
|
|
if (!framingPreset) {
|
|
if (!Float.isFinite(avatarFrameZoom) || avatarFrameZoom < 1f || avatarFrameZoom > 2f ||
|
|
!Float.isFinite(avatarFrameCenterY) || avatarFrameCenterY < 0.4f || avatarFrameCenterY > 0.6f) throw new GradleException('Invalid avatar framing')
|
|
if ((avatarFrameZoom != 1f || avatarFrameCenterY != 0.5f) &&
|
|
(!avatarUserAssetCandidate || characterMediaId != 'black-correct03')) throw new GradleException('Framing candidate requires exact black media')
|
|
} else if (framingPresetId != 'square540-headchest' || avatarFrameZoom != 3.5555556f || avatarFrameCenterY != 0.128125f) throw new GradleException('Invalid controlled square framing')
|
|
if (emotionManifestSha && !(emotionManifestSha ==~ /[0-9a-f]{64}/)) throw new GradleException('Emotion graph requires exact external manifest SHA')
|
|
if (emotionManifestSha && (!avatarActionCandidate || !avatarMouthCandidate || !avatarNatural || actionVersionCode < 17)) throw new GradleException('Emotion candidate requires own-mouth runtime and a fresh code >=17')
|
|
if (avatarFullActionCandidate && (!emotionManifestSha || !avatarActionCandidate || actionVersionCode < 18)) throw new GradleException('Full candidate requires pinned emotion/action graph and fresh code >=18')
|
|
if (cameraCompatibilityFix && (!faceDiagnosticsFix || actionVersionCode < 25)) throw new GradleException('Camera compatibility requires face diagnostics and fresh code >=25')
|
|
if (cameraDirectYuv && (!cameraCompatibilityFix || actionVersionCode < 26)) throw new GradleException('Direct YUV validation requires camera diagnostics and fresh code >=26')
|
|
if (cameraProbeDiagnostic && (!cameraPreviewStream || actionVersionCode < 29)) throw new GradleException('Camera probe diagnostics requires fresh code >=29')
|
|
if (cameraPreviewStream && (!cameraDirectYuv || actionVersionCode < 27)) throw new GradleException('Preview stream validation requires camera diagnostics and fresh code >=27')
|
|
if (faceDiagnosticsFix && (!presenceCandidate || actionVersionCode < 24)) throw new GradleException('Face diagnostics fix requires presence and fresh code >=24')
|
|
if (presenceCandidate && (!avatarStartupFix || actionVersionCode < 23)) throw new GradleException('Presence candidate requires startup fix and fresh code >=23')
|
|
if (avatarStartupFix && (!avatarPlaybackClockFix || actionVersionCode < 22)) throw new GradleException('Startup fix requires repaired playback and fresh code >=22')
|
|
if (avatarUserNetworkActions && (!avatarUserAssetCandidate || actionVersionCode < 32)) throw new GradleException('User network dance requires authorized exact asset mode and fresh code >=32')
|
|
if (avatarUserAssetCandidate && (!avatarStartupFix || !cameraProbeDiagnostic || actionVersionCode < (characterMedia.minimumVersionCode ?: 30) || characterMedia.userAuthorizedDebug != true || emotionManifestSha != characterMedia.indexSha256)) throw new GradleException('User asset debug candidate requires exact authorized media, startup and current diagnostics, fresh code')
|
|
if (!avatarUserAssetCandidate && avatarPlaybackClockFix && (!avatarFullActionCandidate || actionVersionCode < 21 || emotionManifestSha != '987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887')) throw new GradleException('Playback clock fix requires frozen full graph and fresh code >=21')
|
|
if (avatarPlaybackDiagnostic && (!avatarFullActionCandidate || actionVersionCode < 20 || emotionManifestSha != '987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887')) throw new GradleException('Playback diagnostic requires frozen full graph and fresh code >=20')
|
|
if (avatarRuntimeFix && (!avatarFullActionCandidate || actionVersionCode < 19)) throw new GradleException('Runtime fix requires full pinned graph and fresh code >=19')
|
|
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')
|
|
}
|
|
}
|
|
|
|
// Explicit common assets, runtime references, bootstrap and code29 fallback retention.
|
|
// Unlisted source directories cannot enter mergeAssets.
|
|
def packagedAssets = layout.buildDirectory.dir('generated/packagedAssets')
|
|
def stagePackagedAssets = tasks.register('stagePackagedAssets', Exec) {
|
|
workingDir rootProject.projectDir
|
|
inputs.files(characterCatalogFile, rootProject.file('manifests/retained-avatar-files.json'), rootProject.file('scripts/select-character-assets.py'))
|
|
inputs.dir(file('src/main/assets'))
|
|
inputs.dir(file('src/main/res/drawable-nodpi'))
|
|
if (characterMedia.resourceDirectory) inputs.dir(rootProject.file(characterMedia.resourceDirectory))
|
|
inputs.property('selection', [characterProfileId, framingPresetId, characterMediaId, emotionManifestSha, avatarUserAssetCandidate, avatarMouthCandidate, avatarStartupFix].toString())
|
|
outputs.dir(packagedAssets)
|
|
outputs.file(layout.buildDirectory.file('generated/character-selection.json'))
|
|
commandLine 'python3', rootProject.file('scripts/select-character-assets.py'), '--profile', characterProfileId,
|
|
'--media-bundle', emotionManifestSha ? characterMediaId : '',
|
|
'--assets', file('src/main/assets'), '--emotion-sha', emotionManifestSha,
|
|
'--user-assets', avatarUserAssetCandidate.toString(), '--mouth', avatarMouthCandidate.toString(),
|
|
'--startup', avatarStartupFix.toString(), '--output', packagedAssets.get().asFile,
|
|
'--report', layout.buildDirectory.file('generated/character-selection.json').get().asFile
|
|
}
|
|
|
|
android {
|
|
namespace 'com.gorios.lanvoice'
|
|
compileSdk 34
|
|
defaultConfig {
|
|
applicationId characterProfile.applicationId
|
|
manifestPlaceholders = [characterAllowBackup: characterProfile.allowBackup.toString()]
|
|
resValue 'string', 'character_app_name', characterProfile.appName
|
|
buildConfigField 'String', 'CHARACTER_PROFILE', groovy.json.JsonOutput.toJson(characterProfileId)
|
|
buildConfigField 'String', 'DIALOGUE_PERSONA', groovy.json.JsonOutput.toJson(characterProfile.persona)
|
|
buildConfigField 'String', 'CHARACTER_NOTE', groovy.json.JsonOutput.toJson(characterMedia.settingsNote ?: characterProfile.settingsNote)
|
|
buildConfigField 'boolean', 'PERMISSION_CONNECTION_RETENTION', characterProfile.permissionConnectionRetention.toString()
|
|
minSdk 26
|
|
targetSdk 34
|
|
testInstrumentationRunner 'com.gorios.lanvoice.AvatarCleanUiInstrumentation'
|
|
versionCode avatarActionCandidate ? actionVersionCode : (avatarMouthCandidate ? 15 : (avatarUiCandidate ? 14 : (avatarNatural ? 13 : 12)))
|
|
versionName = avatarUserNetworkActions ? '0.7.14' : avatarUserAssetCandidate ? '0.7.12' : cameraProbeDiagnostic ? '0.7.11' : cameraPreviewStream ? '0.7.9' : cameraDirectYuv ? '0.7.8' : cameraCompatibilityFix ? '0.7.7' : faceDiagnosticsFix ? '0.7.6' : presenceCandidate ? '0.7.5' : avatarStartupFix ? '0.7.4' : avatarPlaybackClockFix ? '0.7.3' : avatarPlaybackDiagnostic ? '0.7.2' : avatarRuntimeFix ? '0.7.1' : (avatarActionCandidate ? '0.7.0' : ((avatarUiCandidate || avatarMouthCandidate) ? '0.6.2' : '0.6.1'))
|
|
ndk { abiFilters 'arm64-v8a' }
|
|
if (characterProfile.versionBase) versionName = characterProfile.versionBase
|
|
versionName += characterProfile.versionSuffix
|
|
}
|
|
compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }
|
|
kotlinOptions { jvmTarget = '17' }
|
|
buildFeatures { compose true; buildConfig true }
|
|
buildTypes {
|
|
debug {
|
|
if (avatarFullActionCandidate) { /* Full reviewed debug integration candidate: 0.7.0 */ }
|
|
else if (emotionManifestSha) versionNameSuffix '-emotion-dev'
|
|
else 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_NETWORK_ACTIONS_ALLOWED', (!avatarUserAssetCandidate || avatarUserNetworkActions) ? 'true' : 'false'
|
|
buildConfigField 'boolean', 'AVATAR_USER_ASSET_CANDIDATE', avatarUserAssetCandidate ? 'true' : 'false'
|
|
buildConfigField 'boolean', 'WAITING_POSES_ENABLED', characterMedia.waitingContract == true ? 'true' : 'false'
|
|
buildConfigField 'String', 'EMOTION_ASSET_ROOT', groovy.json.JsonOutput.toJson(characterMedia.assetRoot)
|
|
buildConfigField 'String', 'STARTUP_ASSET_ROOT', groovy.json.JsonOutput.toJson(characterMedia.bootstrapRoot)
|
|
buildConfigField 'String', 'STARTUP_MANIFEST_SHA', groovy.json.JsonOutput.toJson(characterMedia.bootstrapSha256)
|
|
buildConfigField 'int', 'STARTUP_POSTER_RES_ID', 'com.gorios.lanvoice.R.drawable.' + characterMedia.posterResource
|
|
buildConfigField 'String', 'AVATAR_FRAMING_PRESET', groovy.json.JsonOutput.toJson(framingPresetId)
|
|
buildConfigField 'float', 'AVATAR_FRAME_ZOOM', avatarFrameZoom.toString() + 'f'
|
|
buildConfigField 'float', 'AVATAR_FRAME_CENTER_Y', avatarFrameCenterY.toString() + 'f'
|
|
buildConfigField 'boolean', 'CAMERA_PROBE_DIAGNOSTIC', cameraProbeDiagnostic ? 'true' : 'false'
|
|
buildConfigField 'boolean', 'AVATAR_STARTUP_FIX', avatarStartupFix ? 'true' : 'false'
|
|
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_NETWORK_ACTIONS_ALLOWED', 'false'
|
|
buildConfigField 'boolean', 'AVATAR_USER_ASSET_CANDIDATE', 'false'
|
|
buildConfigField 'boolean', 'WAITING_POSES_ENABLED', 'false'
|
|
buildConfigField 'String', 'EMOTION_ASSET_ROOT', '"avatar/a01-expression-action-v1/"'
|
|
buildConfigField 'String', 'STARTUP_ASSET_ROOT', '"avatar/startup-white-01/"'
|
|
buildConfigField 'String', 'STARTUP_MANIFEST_SHA', '"461f5cfc10036de5f10ca3ce765fb8d9998697d3fd035aa9b1862d2ccfc3eaa2"'
|
|
buildConfigField 'int', 'STARTUP_POSTER_RES_ID', 'com.gorios.lanvoice.R.drawable.startup_poster'
|
|
buildConfigField 'String', 'AVATAR_FRAMING_PRESET', '"legacy"'
|
|
buildConfigField 'float', 'AVATAR_FRAME_ZOOM', '1.0f'
|
|
buildConfigField 'float', 'AVATAR_FRAME_CENTER_Y', '0.5f'
|
|
buildConfigField 'boolean', 'CAMERA_PROBE_DIAGNOSTIC', 'false'
|
|
buildConfigField 'boolean', 'AVATAR_STARTUP_FIX', 'false'
|
|
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)
|
|
if (characterMedia.resourceDirectory) sourceSets.main.res.srcDir(rootProject.file(characterMedia.resourceDirectory))
|
|
// 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) }
|
|
androidComponents {
|
|
beforeVariants(selector().withBuildType('release')) { variant ->
|
|
if (characterProfileId != 'main') variant.enable = false
|
|
}
|
|
}
|
|
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"
|
|
}
|