diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index 96da316d96dc44..b1ba75be257e28 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -478,6 +478,55 @@ val packageReactNdkLibsForBuck by into("src/main/jni/prebuilt/lib") } +// Derivative of the packageReactNdkDebugLibsForBuck task, appends "debug" to the "into" dir +val packageReactNdkDebugLibsForDiscord by + tasks.registering(Copy::class) { + dependsOn("mergeDebugNativeLibs") + // Shared libraries (.so) are copied from the merged_native_libs folder instead + from("$buildDir/intermediates/merged_native_libs/debug/out/lib/") + exclude("**/libjsc.so") + exclude("**/libhermes.so") + into("src/main/jni/prebuilt/lib/debug") + } + +// Derivative of the packageReactNdkReleaseLibsForBuck task, appends "release" to the "into" dir +val packageReactNdkReleaseLibsForDiscord by + tasks.registering(Copy::class) { + dependsOn("mergeReleaseNativeLibs") + // Shared libraries (.so) are copied from the merged_native_libs folder instead + from("$buildDir/intermediates/merged_native_libs/release/out/lib/") + exclude("**/libjsc.so") + exclude("**/libhermes.so") + into("src/main/jni/prebuilt/lib/release") + } + +val createReactNdkLibraryZipArchiveForDiscord by + tasks.registering(Zip::class) { + // This dependsOn tasks gets all our *.so files into the src/main/jni/prebuilt/lib directory + dependsOn("packageReactNdkDebugLibsForDiscord") + dependsOn("packageReactNdkReleaseLibsForDiscord") + + // A searchable self-documenting name for the build process, but its final packaged name will end up being react-native-{version}.zip + archiveFileName.set("ReactNativeLibrariesForDiscord.zip") + from(layout.projectDirectory.dir("src/main/jni/prebuilt")) { + // Get all *.so files in the prebuilt directory + include("**/*.so") + val fileCopyAction = object: Action { + override fun execute(fcd: FileCopyDetails) { + // Trim down each file's directory to just include the "lib/{debug/release}/{architecture}" part + val relativeFileName = RelativePath(true, *fcd.relativePath.segments.takeLast(4).toTypedArray()) + fcd.relativePath = relativeFileName + } + } + eachFile(fileCopyAction) + // Removes empty dirs resulting from the eachFile directory remapping above + includeEmptyDirs = false + } + + // Place this .zip right into our ReactAndroid directory + destinationDirectory.set(layout.projectDirectory) + } + repositories { // Normally RNGP will set repositories for all modules, // but when consumed from source, we need to re-declare @@ -810,5 +859,15 @@ apply(from = "./publish.gradle") // Please note that the original coordinates, `react-native`, have been voided // as they caused https://github.com/facebook/react-native/issues/35210 publishing { - publications { getByName("release", MavenPublication::class) { artifactId = "react-android" } } + publications { + getByName("release", MavenPublication::class) { + artifactId = "react-android" + } + create("libZip") { + groupId = "com.facebook.react" + version = "test" + artifactId = "discord-rn-libs" + artifact(tasks.named("createReactNdkLibraryZipArchiveForDiscord").get()) + } + } } diff --git a/packages/react-native/ReactAndroid/publish.gradle b/packages/react-native/ReactAndroid/publish.gradle index 32287a7c81392c..2e44520d6620cb 100644 --- a/packages/react-native/ReactAndroid/publish.gradle +++ b/packages/react-native/ReactAndroid/publish.gradle @@ -68,6 +68,10 @@ publishing { name = "mavenTempLocal" url = mavenTempLocalUrl } + maven { + name = "discord" + url = uri("gcs://discord-maven") + } } if (signingKey && signingPwd) {