Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / communicate / build.gradle.kts

build.gradle.kts230 lines · 9.4 KiBRaw
1import java.util.Locale
2import javax.inject.Inject
3import org.gradle.api.DefaultTask
4import org.gradle.api.file.DirectoryProperty
5import org.gradle.api.file.RegularFileProperty
6import org.gradle.api.tasks.InputDirectory
7import org.gradle.api.tasks.InputFile
8import org.gradle.api.tasks.OutputDirectory
9import org.gradle.api.tasks.TaskAction
10import org.gradle.process.ExecOperations
11
12plugins {
13 id("common-conventions-app")
14 // Store-listing screenshots rendered from Compose @Preview (car views).
15 id("common-conventions-preview-metadata")
16 id("com.google.devtools.ksp")
17}
18
19launcherIcon {
20 symbol = "call"
21}
22
23android {
24 defaultConfig {
25 applicationId = "com.vayunmathur.communicate"
26 }
27 compileOptions {
28 isCoreLibraryDesugaringEnabled = true
29 }
30 packaging {
31 resources {
32 // libsignal-client bundles its desktop JNI natives (macOS .dylib,
33 // Windows .dll) as Java resources. They can never load on Android and
34 // add ~40 MB to the APK — strip them. The Android lib/arm64-v8a/
35 // libsignal_jni.so is unaffected.
36 excludes += setOf("**/*.dylib", "*.dylib", "**/*.dll", "*.dll")
37 }
38 jniLibs {
39 // Test-only libsignal native (NativeTesting bridge); unused in prod.
40 excludes += "**/libsignal_jni_testing.so"
41 }
42 }
43}
44
45dependencies {
46 coreLibraryDesugaring(libs.desugar.jdk.libs)
47}
48
49// ----------------------------------------------------------------
50// Protobuf code generation (manual)
51// ----------------------------------------------------------------
52//
53// Both `com.squareup.wire` and `com.google.protobuf` Gradle plugins fail
54// to apply to this module because they try to cast AGP 9's
55// `ApplicationExtensionImpl` to the legacy `BaseExtension`, which AGP 9
56// removed. Until those plugins catch up, we resolve `protoc` from Maven
57// Central and invoke it directly. The resulting Java classes (lite
58// runtime) are added to the variant's Java sources via the AGP
59// `androidComponents` extension below.
60
61val osClassifier: String = run {
62 val osName = System.getProperty("os.name").lowercase(Locale.US)
63 val arch = System.getProperty("os.arch").lowercase(Locale.US)
64 val os = when {
65 osName.contains("mac") || osName.contains("darwin") -> "osx"
66 osName.contains("win") -> "windows"
67 else -> "linux"
68 }
69 val cpu = when {
70 arch.contains("aarch64") || arch.contains("arm64") -> "aarch_64"
71 arch.contains("64") -> "x86_64"
72 else -> "x86_32"
73 }
74 "$os-$cpu"
75}
76
77val protocConfig: Configuration = configurations.create("protocBinary") {
78 isCanBeResolved = true
79 isCanBeConsumed = false
80}
81
82dependencies {
83 "protocBinary"("${libs.protobuf.protoc.get()}:$osClassifier@exe")
84}
85
86val protoSrcDir = layout.projectDirectory.dir("src/main/proto")
87val protoGenDir = layout.buildDirectory.dir("generated/source/proto/java")
88
89// Custom task class so we can inject ExecOperations cleanly (the
90// configuration cache rejects capturing the Project at execution time).
91abstract class GenerateProtoTask @Inject constructor(
92 private val exec: ExecOperations,
93) : DefaultTask() {
94 @get:InputFile
95 abstract val protocBinary: RegularFileProperty
96
97 @get:InputDirectory
98 abstract val protoSourceDir: DirectoryProperty
99
100 @get:OutputDirectory
101 abstract val outputDir: DirectoryProperty
102
103 @TaskAction
104 fun run() {
105 val binary = protocBinary.get().asFile
106 binary.setExecutable(true)
107 val out = outputDir.get().asFile
108 out.deleteRecursively()
109 out.mkdirs()
110 val srcDir = protoSourceDir.get().asFile
111 val protoFiles = srcDir.walkTopDown()
112 .filter { it.isFile && it.extension == "proto" }
113 .toList()
114 if (protoFiles.isEmpty()) return
115 exec.exec {
116 commandLine = buildList {
117 add(binary.absolutePath)
118 add("--java_out=${out.absolutePath}")
119 add("-I=${srcDir.absolutePath}")
120 addAll(protoFiles.map { it.absolutePath })
121 }
122 }
123 }
124}
125
126val generateProto = tasks.register<GenerateProtoTask>("generateProto") {
127 protocBinary.set(layout.file(protocConfig.elements.map { it.single().asFile }))
128 protoSourceDir.set(protoSrcDir)
129 outputDir.set(protoGenDir)
130}
131
132// Make Kotlin/Java/KSP compilation wait on protoc. KSP runs ahead of
133// compileKotlin so it has to be in this list too.
134tasks.matching {
135 it.name.startsWith("compile") &&
136 (it.name.endsWith("Kotlin") || it.name.endsWith("JavaWithJavac")) ||
137 it.name.startsWith("ksp")
138}.configureEach {
139 dependsOn(generateProto)
140}
141
142androidComponents {
143 onVariants { variant ->
144 // Wire proto gen sources + Rust JNI libs into each variant.
145 variant.sources.java?.addStaticSourceDirectory(protoGenDir.get().asFile.absolutePath)
146 val rustDir = layout.buildDirectory.dir("rustJniLibs").get().asFile.absolutePath
147 variant.sources.jniLibs?.addStaticSourceDirectory(rustDir)
148 }
149}
150
151// Classic Signal protocol v3 (X3DH + Double Ratchet + Sender Keys) for the WhatsApp
152// primary client — Rust impl. Unique crate name to avoid workspace collision with
153// messages' whatsapp_signal.
154rustNativeLib("communicate_signal", "communicate_signal")
155
156// MLS (RFC 9420, OpenMLS) for the RCS line's closed-loop E2EE — separate crate
157// (own dependency tree) with its own JNI lib.
158rustNativeLib("communicate_mls", "communicate_mls", srcDir = "src/main/rust-mls")
159
160dependencies {
161 // Google Voice virtual line: protojson RPCs + SIP-over-WSS transport go through
162 // the repo's own Android-only HTTP/WebSocket stack (no OkHttp/Ktor).
163 implementation(project(":library:network"))
164 // Local Compose image loading for Google Voice MMS previews (remote https + content://).
165 implementation(project(":library:image"))
166 // RingRTC supplies both Signal's calling engine and the org.webrtc classes every line's calling
167 // uses. It bundles its own WebRTC, so no other WebRTC distribution can be on the classpath: the two
168 // ship ~368 identical org.webrtc class names, and RingRTC's native library binds to that exact
169 // package via JNI symbol names and FindClass descriptors, so relocating it is not an option either.
170 implementation(libs.ringrtc.android)
171 // E.164 normalization to reconcile SIM vs Google Voice numbers.
172 implementation(libs.libphonenumber)
173 // Compile-only stubs for the framework's @SystemApi app-data backup transport
174 // and single-registration RCS APIs (SipDelegateManager, UCE). Absent from the
175 // public SDK; the framework provides them at runtime, so they must NOT be
176 // packaged. See :library:aosp-stubs.
177 compileOnly(project(":library:aosp-stubs"))
178 // Persist the Google Voice / WhatsApp session (cookies, API key, auth, number).
179 implementation(libs.androidx.datastore.preferences)
180 // Document-start JS injection to hook fetch/XHR before the GV web app captures them.
181 implementation(libs.androidx.webkit)
182
183 // ---- WhatsApp primary client ----
184 // Room - E2E state + message/thread/reaction/poll cache (communicate's first Room DB).
185 implementRoom(libs)
186 implementation(project(":library:room"))
187
188 // Protobuf runtime — full Java variant. This module only touches ByteString and
189 // InvalidProtocolBufferException, both of which javalite also has, so the switch to lite
190 // is feasible; it is deferred because it regenerates all 11 Signal/WhatsApp protos and
191 // changes toString() and unknown-field semantics on live messaging paths.
192 implementation(libs.protobuf.java)
193
194 // ZXing core — QR code encoding only (no scanner UI). Retained for parity with the
195 // messages port; unused by the primary registration flow.
196 implementation(libs.zxing.core)
197
198 // Signal protocol crypto (Double Ratchet, sealed sender, pre-keys, etc.).
199 // Also provides certificate verification (ECPublicKey.verifySignature) for the WhatsApp
200 // Noise handshake cert chain.
201 implementation(libs.libsignal.android)
202
203 // kotlinx.serialization — session/auth data persistence + serviceData blob.
204 implementation(libs.kotlinx.serialization.json)
205
206 // Car templates (P-car-dock): AndroidX Car App Library, same pairing as
207 // :maps. Only pulled into the car code path (service/car/) — phone UI,
208 // sync services and crypto paths are untouched.
209 implementation(libs.androidx.car.app)
210 implementation(libs.androidx.car.app.projected)
211
212 // Car-view store-listing screenshots render through the shared host renderer.
213 add("screenshotTestImplementation", project(":library:carhost"))
214
215 // Voicemail tab audio playback: plain ExoPlayer (no session/controller stack —
216 // voicemail clips are short local files, not a browsable media library).
217 implementation(libs.androidx.media3.exoplayer)
218
219 // voicemailNumber() reads TelephonyManager.voiceMailNumber, which the unit-test stub
220 // android.jar does not implement ("not mocked"). Robolectric supplies the framework
221 // shadows so the pilot lookup (and its permission/dual-SIM fallbacks) can be asserted
222 // on the JVM; same reason emergency/pdf use it.
223 testImplementation(libs.robolectric)
224 testImplementation(libs.androidx.test.core)
225 // Route slice-6 contract tests use KClass reflection (sealedSubclasses, constructors).
226 testImplementation(libs.kotlin.reflect)
227 // RCS slice tests: real in-memory Room database via the bundled sqlite driver
228 // (same pattern as :todo's TodoMigrationTest).
229 testImplementation(libs.androidx.sqlite.bundled.jvm)
230}