From 1e51ac2b6ccedcc6595788fac7c4dff33d63b16d Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 5 Apr 2022 09:38:55 -0700 Subject: [PATCH] Setup multi-variant publishing for React Native Android (#33539) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/33539 As we now provide `hermes-executor-debug` OR `hermes-executor-release` based on which version of RN we're building, we need to provide a variant aware AAR. Changelog: [Internal] [Changed] - Setup multi-variant publishing for React Native Android Reviewed By: ShikaSD Differential Revision: D35289444 fbshipit-source-id: ffccd2089dc2eb50ea8c08ed10d8fd9816f9efb7 --- ReactAndroid/build.gradle | 26 +++++++++++--------------- scripts/publish-npm.js | 13 +++++++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 53a3f53d8823d0..ab92cf0d569837 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -244,13 +244,7 @@ final def extractNativeDependencies = tasks.register('extractNativeDependencies' } task installArchives { - dependsOn("publishReleasePublicationToNpmRepository") -} - -// Creating sources with comments -task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.srcDirs + dependsOn("publishAllPublicationsToNpmRepository") } android { @@ -358,12 +352,19 @@ android { configurations { extractHeaders extractJNI - javadocDeps.extendsFrom api } buildFeatures { prefab true } + + publishing { + multipleVariants { + withSourcesJar() + withJavadocJar() + allVariants() + } + } } dependencies { @@ -390,8 +391,6 @@ dependencies { // Therefore hermes-engine is a compileOnly dependency. compileOnly(project(":ReactAndroid:hermes-engine")) - javadocDeps("com.squareup:javapoet:1.13.0") - testImplementation("junit:junit:${JUNIT_VERSION}") testImplementation("org.powermock:powermock-api-mockito2:${POWERMOCK_VERSION}") testImplementation("org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}") @@ -431,11 +430,8 @@ afterEvaluate { publishing { publications { release(MavenPublication) { - // Applies the component for the release build variant. - from components.release - - // Add additional sourcesJar to artifacts - artifact(androidSourcesJar) + // We do a multi variant release + from components.default // You can then customize attributes of the publication as shown below. artifactId = POM_ARTIFACT_ID diff --git a/scripts/publish-npm.js b/scripts/publish-npm.js index 082776561727bc..776526e1928498 100755 --- a/scripts/publish-npm.js +++ b/scripts/publish-npm.js @@ -188,7 +188,16 @@ exec('git checkout ReactAndroid/gradle.properties'); echo('Generated artifacts for Maven'); -let artifacts = ['.aar', '.pom'].map(suffix => { +let artifacts = [ + '.module', + '.pom', + '-debug.aar', + '-release.aar', + '-debug-sources.jar', + '-release-sources.jar', + '-debug-javadoc.jar', + '-release-javadoc.jar', +].map(suffix => { return `react-native-${releaseVersion}${suffix}`; }); @@ -199,7 +208,7 @@ artifacts.forEach(name => { `./android/com/facebook/react/react-native/${releaseVersion}/${name}`, ) ) { - echo(`file ${name} was not generated`); + echo(`Failing as expected file: ${name} was not correctly generated.`); exit(1); } });