import java.util.Locale import javax.inject.Inject import org.gradle.api.DefaultTask import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.gradle.process.ExecOperations plugins { id("common-conventions-library") id("com.google.devtools.ksp") } // Dev-build-only companion library for :communicate (see AGENTS.md). // The host app links this module only from its `dev` variant // (`devImplementation`), so nothing in here is compiled or packaged // into release builds. Package names under // com.vayunmathur.communicate.* are kept where JNI symbol names and // wire/persisted formats freeze them. // ---------------------------------------------------------------- // Protobuf code generation (manual) // ---------------------------------------------------------------- // // Both `com.squareup.wire` and `com.google.protobuf` Gradle plugins fail // to apply under AGP 9 (they cast `ApplicationExtensionImpl` to the legacy // `BaseExtension`, which AGP 9 removed). Until those plugins catch up, we // resolve `protoc` from Maven Central and invoke it directly. The resulting // Java classes (lite runtime) are added to the variant's Java sources via // the `androidComponents` extension below. Moved from :communicate with the // 11 Signal/WhatsApp protos; the generated packages // (`com.vayunmathur.communicate.data.whatsapp.proto`, // `org.whispersystems.signalservice...`, ...) are wire-frozen. val osClassifier: String = run { val osName = System.getProperty("os.name").lowercase(Locale.US) val arch = System.getProperty("os.arch").lowercase(Locale.US) val os = when { osName.contains("mac") || osName.contains("darwin") -> "osx" osName.contains("win") -> "windows" else -> "linux" } val cpu = when { arch.contains("aarch64") || arch.contains("arm64") -> "aarch_64" arch.contains("64") -> "x86_64" else -> "x86_32" } "$os-$cpu" } val protocConfig: Configuration = configurations.create("protocBinary") { isCanBeResolved = true isCanBeConsumed = false } // Catalog coordinate (libs.protobuf.protoc) with the platform-classified // exe artifact selected programmatically instead of a string coordinate // with an appended classifier. val protocDependency = dependencies.create(libs.protobuf.protoc.get()) as org.gradle.api.artifacts.ExternalModuleDependency protocDependency.artifact { classifier = osClassifier type = "exe" } dependencies { "protocBinary"(protocDependency) } val protoSrcDir = layout.projectDirectory.dir("src/main/proto") val protoGenDir = layout.buildDirectory.dir("generated/source/proto/java") // Custom task class so we can inject ExecOperations cleanly (the // configuration cache rejects capturing the Project at execution time). abstract class GenerateProtoTask @Inject constructor( private val exec: ExecOperations, ) : DefaultTask() { @get:InputFile abstract val protocBinary: RegularFileProperty @get:InputDirectory abstract val protoSourceDir: DirectoryProperty @get:OutputDirectory abstract val outputDir: DirectoryProperty @TaskAction fun run() { val binary = protocBinary.get().asFile binary.setExecutable(true) val out = outputDir.get().asFile out.deleteRecursively() out.mkdirs() val srcDir = protoSourceDir.get().asFile val protoFiles = srcDir.walkTopDown() .filter { it.isFile && it.extension == "proto" } .toList() if (protoFiles.isEmpty()) return exec.exec { commandLine = buildList { add(binary.absolutePath) add("--java_out=${out.absolutePath}") add("-I=${srcDir.absolutePath}") addAll(protoFiles.map { it.absolutePath }) } } } } val generateProto = tasks.register("generateProto") { protocBinary.set(layout.file(protocConfig.elements.map { it.single().asFile })) protoSourceDir.set(protoSrcDir) outputDir.set(protoGenDir) } // Make Kotlin/Java/KSP compilation wait on protoc. KSP runs ahead of // compileKotlin so it has to be in this list too. tasks.matching { it.name.startsWith("compile") && (it.name.endsWith("Kotlin") || it.name.endsWith("JavaWithJavac")) || it.name.startsWith("ksp") }.configureEach { dependsOn(generateProto) } androidComponents { onVariants { variant -> // Wire proto gen sources + Rust JNI libs into each variant. variant.sources.java?.addStaticSourceDirectory(protoGenDir.get().asFile.absolutePath) val rustDir = layout.buildDirectory.dir("rustJniLibs").get().asFile.absolutePath variant.sources.jniLibs?.addStaticSourceDirectory(rustDir) } } // Classic Signal protocol v3 (X3DH + Double Ratchet + Sender Keys) for the WhatsApp // primary client — Rust impl. Unique crate name to avoid workspace collision with // messages' whatsapp_signal. rustNativeLib("communicate_signal", "communicate_signal") // MLS (RFC 9420, OpenMLS) for the RCS line's closed-loop E2EE — separate crate // (own dependency tree) with its own JNI lib. rustNativeLib("communicate_mls", "communicate_mls", srcDir = "src/main/rust-mls") // Native-loading and shared-JVM-polluting test classes moved here with the // line code (quarantine rationale inherited from :communicate's split: JNI // libs bind to one classloader per JVM, and the *LineSession / // WhatsAppClient-singleton classes leak process-wide state when batched). rustNativeTests { nativeClasses.addAll( listOf( "com.vayunmathur.communicate.rcs.MlsLifecycleRcsPass3Test", "com.vayunmathur.communicate.rcs.RcsSlice3E2ESupportTest", "com.vayunmathur.communicate.rcs.RcsSlice3Pass2E2ETest", "com.vayunmathur.communicate.rcs.RcsSlice3Pass2FakeTransportTest", "com.vayunmathur.communicate.rcs.RcsSlice3Pass2UiTest", "com.vayunmathur.communicate.signal.RegistrationHttpClientSignalPass3Test", "com.vayunmathur.communicate.signal.RustSignalCryptoSignalPass3Test", "com.vayunmathur.communicate.signal.SignalAuthAndServiceDataTest", "com.vayunmathur.communicate.signal.SignalCallAndTransportParseTest", "com.vayunmathur.communicate.signal.SignalCdsiTest", "com.vayunmathur.communicate.signal.SignalGroupsAndSyncTest", "com.vayunmathur.communicate.signal.SignalIdentitySignalPass3Test", "com.vayunmathur.communicate.signal.SignalInboundPollW1Test", "com.vayunmathur.communicate.signal.SignalSafetyNumberTest", "com.vayunmathur.communicate.signal.SignalSealedSenderTest", "com.vayunmathur.communicate.signal.SignalSlice2E2ETest", "com.vayunmathur.communicate.signal.SignalSlice2InboundTest", "com.vayunmathur.communicate.signal.SignalSlice2MessagingOfflineTest", "com.vayunmathur.communicate.signal.SignalSlice2SealedCacheTest", "com.vayunmathur.communicate.signal.Y1SignalMessagingGroupTest", "com.vayunmathur.communicate.signal.Y1SignalSendPipelineTest", "com.vayunmathur.communicate.signal.Y2SignalSocketRegTest", "com.vayunmathur.communicate.signal.Y3SignalGroupOpsServerTest", "com.vayunmathur.communicate.signal.Y3SignalPipelineServerTest", "com.vayunmathur.communicate.signal.Y3SignalServerApiTest", "com.vayunmathur.communicate.whatsapp.W5Slice1AttestationTest", "com.vayunmathur.communicate.whatsapp.W5Slice1MexRouterTest", "com.vayunmathur.communicate.whatsapp.W5Slice1RegBundleTest", "com.vayunmathur.communicate.whatsapp.WhatsAppAttestationTest", "com.vayunmathur.communicate.whatsapp.WhatsAppRegistrationBadParamRegressionTest", "com.vayunmathur.communicate.whatsapp.Y1WaE2eSyncTest", "com.vayunmathur.communicate.whatsapp.Y1WaInboundTest", "com.vayunmathur.communicate.whatsapp.Y1WaRegistrationHttpTest", "com.vayunmathur.communicate.whatsapp.Y2WaSocketSendTest", "com.vayunmathur.communicate.whatsapp.Y3AppStatePageTest", ) ) isolatedClasses.addAll( listOf( "com.vayunmathur.communicate.rcs.RcsSlice3Pass2DirectSipAuthTest", "com.vayunmathur.communicate.rcs.RcsSlice3Pass2TlsAndFtTest", "com.vayunmathur.communicate.rcs.RcsSlice3Pass2TransportTest", "com.vayunmathur.communicate.whatsapp.W5Pass2ClientCoreTest", "com.vayunmathur.communicate.whatsapp.W5Pass2ContactUtilsTest", "com.vayunmathur.communicate.whatsapp.W5Pass2SyncHistoryTest", ) ) } dependencies { // Shared repo libraries the dev lines use (mirrors :communicate). implementation(project(":library")) implementation(project(":library:ui")) implementation(project(":library:log")) implementation(project(":library:network")) implementation(project(":library:image")) implementation(project(":library:room")) // Room - E2E state + message/thread/reaction/poll caches for the three lines. implementRoom(libs) // Compile-only framework @SystemApi RCS stubs; never packaged. compileOnly(project(":library:aosp-stubs")) implementation(libs.ringrtc.android) implementation(libs.libsignal.android) implementation(libs.protobuf.java) implementation(libs.libphonenumber) implementation(libs.kotlinx.serialization.json) testImplementation(libs.robolectric) testImplementation(libs.androidx.test.core) testImplementation(libs.kotlin.reflect) testImplementation(libs.androidx.sqlite.bundled.jvm) testImplementation(project(":library:aosp-stubs")) }