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 avatarStartupFix = providers.gradleProperty('avatarStartupFix').orNull == 'true' def cameraCompatibilityFix = providers.gradleProperty('cameraCompatibilityFix').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 (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 (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 (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 (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 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/**' if (!avatarStartupFix) exclude 'avatar/startup-white-01/**' if (!emotionManifestSha) exclude 'avatar/a01-expression-action-v1/**' 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 = 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' } } 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_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_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) // 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" }