Skip to content

Commit

Permalink
feat: add prefab and maven publish support (#185)
Browse files Browse the repository at this point in the history
# Why

prepare the future support to publish artifact at maven central.
because people use hermes mostly and it doesn't make sense to download unnecessary jsc-android from npm

# How

- change group:artifact to `io.github.react-native-community:jsc-android`
- add prefabPublishing support. that would help react-native integration easier
  • Loading branch information
Kudo authored Nov 26, 2024
1 parent 4a89838 commit 9c61fec
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 88 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -91,6 +94,13 @@ jobs:
name: archive
path: archive

- name: Extract archive
run: |
mv archive/dist dist
mv archive/dist.unstripped dist.unstripped
rmdir archive
shell: bash

- name: 🍺 Install Maestro
run: |
curl -Ls "https://get.maestro.mobile.dev" | bash
Expand All @@ -115,6 +125,20 @@ jobs:
target: google_apis
working-directory: test
script: |
mv ../archive/dist ../dist
npx expo run:android --variant release --no-bundler
adb logcat -c
set +e
maestro test maestro.yaml
STATUS=$?
adb logcat -d > adb.log
exit $STATUS
- name: Upload failed artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: failure_artifacts
path: |
$HOME/.maestro/tests/**/*
test/android/app/build/outputs/apk/release/app-release.apk
test/adb.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package-lock.json
bin/
gen/
out/
.cxx/

# Gradle files
.gradle/
Expand Down
65 changes: 0 additions & 65 deletions lib/android-jsc/build.gradle

This file was deleted.

14 changes: 7 additions & 7 deletions lib/cppruntime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ apply plugin: 'maven-publish'

def distDir = project.findProperty("distDir") ?: ""
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")
def version = project.findProperty("version") ?: "".replaceAll("\\s", "")

if (!distDir) throw new RuntimeException("expecting --project-prop distDir=??? but was empty")
if (!jniLibsDir) throw new RuntimeException("expecting --project-prop jniLibsDir=??? but was empty")
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
if (!version) throw new RuntimeException("expecting --project-prop version=??? but was empty")

android {
namespace 'org.webkit.androidjsc_cppruntime'
namespace 'io.github.react_native_community.jscandroid_cppruntime'
compileSdkVersion 35

defaultConfig {
Expand All @@ -34,17 +34,17 @@ android {

dependencies {}

project.group = "org.webkit"
project.version = "r${revision}"
project.group = "io.github.react-native-community"
project.version = "${version}"

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
pom {
name = "android-jsc"
artifactId = "android-jsc-cppruntime"
name = "jsc-android"
artifactId = "jsc-android-cppruntime"
packaging = "aar"
}
}
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions lib/jsc-android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
project(jsc-android)

add_library(jsc SHARED empty.cpp)

set(OUTPUT_SRC "${PREBUILT_LIBS_DIR}/${ANDROID_ABI}/libjsc.so")
set(OUTPUT_DST "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libjsc.so")

add_custom_command(
TARGET jsc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${OUTPUT_SRC}
${OUTPUT_DST}
COMMENT "Overwriting ${OUTPUT_SRC} to ${OUTPUT_DST}"
)
123 changes: 123 additions & 0 deletions lib/jsc-android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

def distDir = project.findProperty("distDir") ?: ""
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
def headersDir = project.findProperty("headersDir") ?: "${distDir}/include"
def version = project.findProperty("version") ?: "".replaceAll("\\s", "")
def i18n = project.findProperty("i18n") ?: ""

def signingKey = project.findProperty('signingKey')
def signingPassword = project.findProperty('signingPassword')

if (!distDir) throw new RuntimeException("expecting --project-prop distDir=??? but was empty")
if (!jniLibsDir) throw new RuntimeException("expecting --project-prop jniLibsDir=??? but was empty")
if (!version) throw new RuntimeException("expecting --project-prop version=??? but was empty")
if (!i18n) throw new RuntimeException("expecting --project-prop i18n=??? but was empty")

android {
namespace 'io.github.react_native_community.jscandroid'
compileSdkVersion 35

defaultConfig {
minSdkVersion 24
targetSdkVersion 34
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared',
"-DPREBUILT_LIBS_DIR=${jniLibsDir}"
targets 'jsc'
}
}
}

externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}

packagingOptions {
doNotStrip '**/libjsc.so'
pickFirst '**/libjsc.so'

excludes += [
'**/libc++_shared.so',
]
}

buildFeatures {
prefabPublishing true
}

prefab {
jsc {
headers file(headersDir).absolutePath
}
}

publishing {
singleVariant("release") {
}
}
}

dependencies {}

project.group = "io.github.react-native-community"
def artifactName = Boolean.valueOf(i18n) ? "jsc-android-intl" : "jsc-android"
project.version = "${version}"

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
pom {
name = artifactName
artifactId = artifactName
description = 'Pre-build version of JavaScriptCore to be used by React Native apps'
url = 'https://github.com/react-native-community/jsc-android-buildscripts'

developers {
developer {
id = 'react-native-community'
name = 'React Native Community'
}
}

licenses {
license {
name = 'BSD-2-Clause'
url = 'https://github.com/react-native-community/jsc-android-buildscripts/blob/main/LICENSE'
distribution = 'repo'
}
}

scm {
url = 'https://github.com/react-native-community/jsc-android-buildscripts.git'
connection = 'scm:git:https://github.com/react-native-community/jsc-android-buildscripts.git'
developerConnection = 'scm:git:[email protected]:react-native-community/jsc-android-buildscripts.git'
}
}
}
}

repositories {
maven {
url = "file://${distDir}"
}
}

if (signingKey && signingPassword) {
signing {
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.release
}
}
}
}
Empty file added lib/jsc-android/empty.cpp
Empty file.
2 changes: 1 addition & 1 deletion lib/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'JavaScriptCore Lib'

include ':android-jsc'
include ':jsc-android'
include ':cppruntime'
6 changes: 3 additions & 3 deletions measure/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ext {
JSC_VERSION = jscAAR ? file(file(jscAAR).getParent()).getName() : ""

def i18nProp = project.findProperty("i18n")
JSC_NAME = Boolean.valueOf(i18nProp) ? "android-jsc-intl" : "android-jsc"
JSC_NAME = Boolean.valueOf(i18nProp) ? "jsc-android-intl" : "jsc-android"

isIDE = System.getProperties()['idea.platform.prefix'] != null
}
Expand All @@ -18,7 +18,7 @@ if (!isIDE && JSC_VERSION) {
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'android-jsc') {
if (details.requested.name == 'jsc-android') {
details.useTarget group: details.requested.group, name: JSC_NAME, version: JSC_VERSION
}
}
Expand All @@ -43,7 +43,7 @@ buildscript {

allprojects {
repositories {
// this tells gradle where android-jsc resides
// this tells gradle where jsc-android resides
maven {
url JSC_DIR
}
Expand Down
18 changes: 10 additions & 8 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ createAAR() {
local distDir=$2
local jniLibsDir=$3
local i18n=$4
local headersDir=${distDir}/include
printf "\n\n\t\t===================== create aar :${target}: =====================\n\n"
cd $ROOTDIR/lib
./gradlew clean :${target}:publish \
--project-prop distDir="${distDir}" \
--project-prop jniLibsDir="${jniLibsDir}" \
--project-prop revision="$REVISION" \
--project-prop headersDir="${headersDir}" \
--project-prop version="${npm_package_version}" \
--project-prop i18n="${i18n}"
cd $ROOTDIR
}
Expand All @@ -104,19 +106,19 @@ export I18N=true
prep
compile

export DISTDIR=${ROOTDIR}/dist
printf "\n\n\t\t===================== create stripped distributions =====================\n\n"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
export DISTDIR=${ROOTDIR}/dist
copyHeaders ${DISTDIR}
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"

printf "\n\n\t\t===================== create unstripped distributions =====================\n\n"
export DISTDIR=${ROOTDIR}/dist.unstripped
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
copyHeaders ${DISTDIR}
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"

npm run info

Expand Down
3 changes: 2 additions & 1 deletion test/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"web": {
"favicon": "./assets/favicon.png"
},
"jsEngine": "jsc"
"jsEngine": "jsc",
"plugins": ["./plugins/withJscAndroid"]
}
}
3 changes: 1 addition & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"postinstall": "rm -rf node_modules/jsc-android/dist && cd node_modules/jsc-android && ln -s ../../../dist"
"web": "expo start --web"
},
"dependencies": {
"expo": "~52.0.7",
Expand Down
Loading

0 comments on commit 9c61fec

Please sign in to comment.