apply plugin: 'com.android.library' apply plugin: 'com.facebook.react' apply plugin: 'maven-publish' android { compileSdkVersion rootProject.ext.compileSdkVersion ndkVersion rootProject.ext.ndkVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion buildConfigField "String", "SDK_VERSION", "\"$sdkVersion\"" // Library modules don't get RN's app-mode CMake defaults; set them here. externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON", "-DREACT_ANDROID_DIR=${rootProject.projectDir}/../node_modules/react-native/ReactAndroid", "-DPROJECT_BUILD_DIR=${project.layout.buildDirectory.get().asFile}" } } } buildTypes { debug { buildConfigField "boolean", "LIBRE_BUILD", "${rootProject.ext.libreBuild}" buildConfigField "boolean", "GOOGLE_SERVICES_ENABLED", "${rootProject.ext.googleServicesEnabled}" } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "boolean", "LIBRE_BUILD", "${rootProject.ext.libreBuild}" buildConfigField "boolean", "GOOGLE_SERVICES_ENABLED", "${rootProject.ext.googleServicesEnabled}" } } sourceSets { main { java { exclude "test/" } } } // JNI shim that registers TurboModules so consumers don't need libappmodules.so. externalNativeBuild { cmake { path 'src/main/jni/CMakeLists.txt' } } buildFeatures { prefab true } // Exclude RN core .so files; consumers get them from react-android transitively. packagingOptions { excludes += [ "**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnative.so", "**/libreactnativejni.so", "**/libturbomodulejsijni.so", ] } namespace 'org.jitsi.meet.sdk' } // Generate autolinking.cpp + Android-autolinking.cmake for our CMake to include. def jitsiAutolinkOutDir = layout.buildDirectory.dir('generated/autolinking/src/main/jni') def jitsiGenerateAutolinking = tasks.register('jitsiGenerateAutolinkingNewArchitectureFiles', com.facebook.react.tasks.GenerateAutolinkingNewArchitecturesFileTask) { autolinkInputFile.set(gradle.ext.autolinkingManifest) generatedOutputDirectory.set(jitsiAutolinkOutDir) } // Run autolinking + per-lib codegen before any CMake task — our CMake reads them. gradle.projectsEvaluated { def rootAutolinkConfig = rootProject.tasks.findByName('generateAutolinkingConfigJson') if (rootAutolinkConfig != null) { jitsiGenerateAutolinking.configure { it.dependsOn(rootAutolinkConfig) } } def allCodegenTasks = rootProject.subprojects.collectMany { sub -> sub.tasks.matching { it.name == 'generateCodegenArtifactsFromSchema' } } tasks.matching { it.name.startsWith('configureCMake') || it.name.startsWith('buildCMake') || it.name.startsWith('externalNativeBuildClean') }.configureEach { it.dependsOn(allCodegenTasks) it.dependsOn(jitsiGenerateAutolinking) } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.fragment:fragment:1.4.1' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' api "com.facebook.react:react-android:$rootProject.ext.rnVersion" api "com.facebook.hermes:hermes-android:$rootProject.ext.hermesVersion" implementation 'com.dropbox.core:dropbox-core-sdk:4.0.1' implementation 'com.jakewharton.timber:timber:5.0.1' implementation 'com.google.code.gson:gson:2.8.6' implementation 'androidx.startup:startup-runtime:1.1.0' implementation 'com.google.j2objc:j2objc-annotations:3.0.0' // Autolinked RN modules come from settings.gradle; only the special cases below differ. // webrtc uses `api` so consumers can access WebRTCModuleOptions. def rnApiModules = [':react-native-webrtc'] def rnModuleExcludes = [ (':react-native-device-info') : ['com.google.firebase', 'com.google.android.gms', 'com.android.installreferrer'], (':react-native-google-signin-google-signin') : ['com.google.android.gms', 'androidx'] ] // LIBRE_BUILD exclusions happen in settings.gradle. (gradle.ext.autolinkedProjects ?: []).each { path -> def conf = rnApiModules.contains(path) ? 'api' : 'implementation' dependencies.add(conf, project(path)) { rnModuleExcludes.getOrDefault(path, []).each { grp -> exclude group: grp } } } testImplementation 'junit:junit:4.12' } // Here we bundle all assets, resources and React files. We cannot use the // react.gradle file provided by react-native because it's designed to be used // in an application (it taps into applicationVariants, but the SDK is a library // so we need libraryVariants instead). android.libraryVariants.all { def variant -> // Create variant and target names def targetName = variant.name.capitalize() def targetPath = variant.dirName // React js bundle directories def jsBundleDir = file("$buildDir/generated/assets/react/${targetPath}") def resourcesDir = file("$buildDir/generated/res/react/${targetPath}") def jsBundleFile = file("$jsBundleDir/index.android.bundle") def currentBundleTask = tasks.create( name: "bundle${targetName}JsAndAssets", type: Exec) { group = "react" description = "bundle JS and assets for ${targetName}." // Create dirs if they are not there (e.g. the "clean" task just ran) doFirst { jsBundleDir.deleteDir() jsBundleDir.mkdirs() resourcesDir.deleteDir() resourcesDir.mkdirs() } // Set up inputs and outputs so gradle can cache the result def reactRoot = file("${projectDir}/../../") inputs.files fileTree(dir: reactRoot, excludes: ["android/**", "ios/**"]) outputs.dir jsBundleDir outputs.dir resourcesDir // Set up the call to the react-native cli workingDir reactRoot // Set up dev mode def devEnabled = !targetName.toLowerCase().contains("release") commandLine( "node", "node_modules/react-native/scripts/bundle.js", "--platform", "android", "--dev", "${devEnabled}", "--reset-cache", "--entry-file", "index.android.js", "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir) // Disable bundling on dev builds enabled !devEnabled } // Ensure proper task ordering for Gradle 8.14+ strict dependency validation currentBundleTask.configure { mustRunAfter { def config = project.configurations.findByName("${targetPath}CompileClasspath") // Fallback to an empty list(mustRunAfter expects a list, not "null" which is the og fallback), // means no config, means no constraints (config?.allDependencies ?: []) .findAll { it.hasProperty('dependencyProject') } .collectMany { dependency -> project.project(dependency.dependencyProject.path) .tasks.matching { it.name.contains(targetName) } } } } currentBundleTask.ext.generatedResFolders = files(resourcesDir).builtBy(currentBundleTask) currentBundleTask.ext.generatedAssetsFolders = files(jsBundleDir).builtBy(currentBundleTask) variant.registerGeneratedResFolders(currentBundleTask.generatedResFolders) def mergeAssetsTask = variant.mergeAssetsProvider.get() def mergeResourcesTask = variant.mergeResourcesProvider.get() mergeAssetsTask.dependsOn(currentBundleTask) mergeResourcesTask.dependsOn(currentBundleTask) mergeAssetsTask.doLast { def assetsDir = mergeAssetsTask.outputDir.get() // Bundle sounds // copy { from("${projectDir}/../../sounds") include("*.wav") include("*.mp3") into("${assetsDir}/sounds") } // Copy React assets // if (currentBundleTask.enabled) { copy { from(jsBundleFile) into(assetsDir) } } } mergeResourcesTask.doLast { // Copy React resources // if (currentBundleTask.enabled) { copy { from(resourcesDir) into(mergeResourcesTask.outputDir.get()) } } } } publishing { publications { aarArchive(MavenPublication) { groupId 'org.jitsi.react' artifactId 'jitsi-meet-sdk' version System.env.OVERRIDE_SDK_VERSION ?: project.sdkVersion artifact("${project.buildDir}/outputs/aar/${project.name}-release.aar") { extension "aar" } pom.withXml { def pomXml = asNode() pomXml.appendNode('name', 'jitsi-meet-sdk') pomXml.appendNode('description', 'Jitsi Meet SDK for Android') def dependencies = pomXml.appendNode('dependencies') configurations.getByName('releaseCompileClasspath').getResolvedConfiguration().getFirstLevelModuleDependencies().each { // The (third-party) React Native modules that we depend on // are in source code form and do not have groupId. That is // why we have a dedicated groupId for them. But the other // dependencies come through Maven and, consequently, have // groupId. def groupId = it.moduleGroup def artifactId = it.moduleName if (artifactId.contains('react-native')) { groupId = rootProject.ext.moduleGroupId } def dependency = dependencies.appendNode('dependency') dependency.appendNode('groupId', groupId) dependency.appendNode('artifactId', artifactId) dependency.appendNode('version', it.moduleVersion) } } } } repositories { maven { url rootProject.ext.mavenRepo if (!rootProject.ext.mavenRepo.startsWith("file")) { credentials { username rootProject.ext.mavenUser password rootProject.ext.mavenPassword } } } } }