Skip to content

Commit

Permalink
Setup multi-variant publishing for React Native Android (#33539)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 5, 2022
1 parent 6e5cefe commit 1e51ac2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
26 changes: 11 additions & 15 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -358,12 +352,19 @@ android {
configurations {
extractHeaders
extractJNI
javadocDeps.extendsFrom api
}

buildFeatures {
prefab true
}

publishing {
multipleVariants {
withSourcesJar()
withJavadocJar()
allVariants()
}
}
}

dependencies {
Expand All @@ -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}")
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions scripts/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
});

Expand All @@ -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);
}
});
Expand Down

0 comments on commit 1e51ac2

Please sign in to comment.