Skip to content

Commit 9c61fec

Browse files
authored
feat: add prefab and maven publish support (#185)
# 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
1 parent 4a89838 commit 9c61fec

File tree

15 files changed

+268
-88
lines changed

15 files changed

+268
-88
lines changed

.github/workflows/build_and_test.yml

+25-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12+
env:
13+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SIGNING_KEY }}
14+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}
1215

1316
steps:
1417
- uses: actions/checkout@v4
@@ -91,6 +94,13 @@ jobs:
9194
name: archive
9295
path: archive
9396

97+
- name: Extract archive
98+
run: |
99+
mv archive/dist dist
100+
mv archive/dist.unstripped dist.unstripped
101+
rmdir archive
102+
shell: bash
103+
94104
- name: 🍺 Install Maestro
95105
run: |
96106
curl -Ls "https://get.maestro.mobile.dev" | bash
@@ -115,6 +125,20 @@ jobs:
115125
target: google_apis
116126
working-directory: test
117127
script: |
118-
mv ../archive/dist ../dist
119128
npx expo run:android --variant release --no-bundler
129+
adb logcat -c
130+
set +e
120131
maestro test maestro.yaml
132+
STATUS=$?
133+
adb logcat -d > adb.log
134+
exit $STATUS
135+
136+
- name: Upload failed artifacts
137+
if: failure()
138+
uses: actions/upload-artifact@v4
139+
with:
140+
name: failure_artifacts
141+
path: |
142+
$HOME/.maestro/tests/**/*
143+
test/android/app/build/outputs/apk/release/app-release.apk
144+
test/adb.log

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package-lock.json
2020
bin/
2121
gen/
2222
out/
23+
.cxx/
2324

2425
# Gradle files
2526
.gradle/

lib/android-jsc/build.gradle

-65
This file was deleted.

lib/cppruntime/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ apply plugin: 'maven-publish'
33

44
def distDir = project.findProperty("distDir") ?: ""
55
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
6-
def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")
6+
def version = project.findProperty("version") ?: "".replaceAll("\\s", "")
77

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

1212
android {
13-
namespace 'org.webkit.androidjsc_cppruntime'
13+
namespace 'io.github.react_native_community.jscandroid_cppruntime'
1414
compileSdkVersion 35
1515

1616
defaultConfig {
@@ -34,17 +34,17 @@ android {
3434

3535
dependencies {}
3636

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

4040
afterEvaluate {
4141
publishing {
4242
publications {
4343
release(MavenPublication) {
4444
from components.release
4545
pom {
46-
name = "android-jsc"
47-
artifactId = "android-jsc-cppruntime"
46+
name = "jsc-android"
47+
artifactId = "jsc-android-cppruntime"
4848
packaging = "aar"
4949
}
5050
}
File renamed without changes.

lib/jsc-android/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
set(CMAKE_VERBOSE_MAKEFILE on)
3+
project(jsc-android)
4+
5+
add_library(jsc SHARED empty.cpp)
6+
7+
set(OUTPUT_SRC "${PREBUILT_LIBS_DIR}/${ANDROID_ABI}/libjsc.so")
8+
set(OUTPUT_DST "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libjsc.so")
9+
10+
add_custom_command(
11+
TARGET jsc POST_BUILD
12+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
13+
${OUTPUT_SRC}
14+
${OUTPUT_DST}
15+
COMMENT "Overwriting ${OUTPUT_SRC} to ${OUTPUT_DST}"
16+
)

lib/jsc-android/build.gradle

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'maven-publish'
3+
apply plugin: 'signing'
4+
5+
def distDir = project.findProperty("distDir") ?: ""
6+
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
7+
def headersDir = project.findProperty("headersDir") ?: "${distDir}/include"
8+
def version = project.findProperty("version") ?: "".replaceAll("\\s", "")
9+
def i18n = project.findProperty("i18n") ?: ""
10+
11+
def signingKey = project.findProperty('signingKey')
12+
def signingPassword = project.findProperty('signingPassword')
13+
14+
if (!distDir) throw new RuntimeException("expecting --project-prop distDir=??? but was empty")
15+
if (!jniLibsDir) throw new RuntimeException("expecting --project-prop jniLibsDir=??? but was empty")
16+
if (!version) throw new RuntimeException("expecting --project-prop version=??? but was empty")
17+
if (!i18n) throw new RuntimeException("expecting --project-prop i18n=??? but was empty")
18+
19+
android {
20+
namespace 'io.github.react_native_community.jscandroid'
21+
compileSdkVersion 35
22+
23+
defaultConfig {
24+
minSdkVersion 24
25+
targetSdkVersion 34
26+
versionCode 1
27+
versionName "1.0"
28+
29+
externalNativeBuild {
30+
cmake {
31+
arguments '-DANDROID_STL=c++_shared',
32+
"-DPREBUILT_LIBS_DIR=${jniLibsDir}"
33+
targets 'jsc'
34+
}
35+
}
36+
}
37+
38+
externalNativeBuild {
39+
cmake {
40+
path 'CMakeLists.txt'
41+
}
42+
}
43+
44+
packagingOptions {
45+
doNotStrip '**/libjsc.so'
46+
pickFirst '**/libjsc.so'
47+
48+
excludes += [
49+
'**/libc++_shared.so',
50+
]
51+
}
52+
53+
buildFeatures {
54+
prefabPublishing true
55+
}
56+
57+
prefab {
58+
jsc {
59+
headers file(headersDir).absolutePath
60+
}
61+
}
62+
63+
publishing {
64+
singleVariant("release") {
65+
}
66+
}
67+
}
68+
69+
dependencies {}
70+
71+
project.group = "io.github.react-native-community"
72+
def artifactName = Boolean.valueOf(i18n) ? "jsc-android-intl" : "jsc-android"
73+
project.version = "${version}"
74+
75+
afterEvaluate {
76+
publishing {
77+
publications {
78+
release(MavenPublication) {
79+
from components.release
80+
pom {
81+
name = artifactName
82+
artifactId = artifactName
83+
description = 'Pre-build version of JavaScriptCore to be used by React Native apps'
84+
url = 'https://github.com/react-native-community/jsc-android-buildscripts'
85+
86+
developers {
87+
developer {
88+
id = 'react-native-community'
89+
name = 'React Native Community'
90+
}
91+
}
92+
93+
licenses {
94+
license {
95+
name = 'BSD-2-Clause'
96+
url = 'https://github.com/react-native-community/jsc-android-buildscripts/blob/main/LICENSE'
97+
distribution = 'repo'
98+
}
99+
}
100+
101+
scm {
102+
url = 'https://github.com/react-native-community/jsc-android-buildscripts.git'
103+
connection = 'scm:git:https://github.com/react-native-community/jsc-android-buildscripts.git'
104+
developerConnection = 'scm:git:[email protected]:react-native-community/jsc-android-buildscripts.git'
105+
}
106+
}
107+
}
108+
}
109+
110+
repositories {
111+
maven {
112+
url = "file://${distDir}"
113+
}
114+
}
115+
116+
if (signingKey && signingPassword) {
117+
signing {
118+
useInMemoryPgpKeys(signingKey, signingPassword)
119+
sign publishing.publications.release
120+
}
121+
}
122+
}
123+
}

lib/jsc-android/empty.cpp

Whitespace-only changes.

lib/settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
rootProject.name = 'JavaScriptCore Lib'
22

3-
include ':android-jsc'
3+
include ':jsc-android'
44
include ':cppruntime'

measure/android/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ext {
66
JSC_VERSION = jscAAR ? file(file(jscAAR).getParent()).getName() : ""
77

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

1111
isIDE = System.getProperties()['idea.platform.prefix'] != null
1212
}
@@ -18,7 +18,7 @@ if (!isIDE && JSC_VERSION) {
1818
configurations.all {
1919
resolutionStrategy {
2020
eachDependency { DependencyResolveDetails details ->
21-
if (details.requested.name == 'android-jsc') {
21+
if (details.requested.name == 'jsc-android') {
2222
details.useTarget group: details.requested.group, name: JSC_NAME, version: JSC_VERSION
2323
}
2424
}
@@ -43,7 +43,7 @@ buildscript {
4343

4444
allprojects {
4545
repositories {
46-
// this tells gradle where android-jsc resides
46+
// this tells gradle where jsc-android resides
4747
maven {
4848
url JSC_DIR
4949
}

scripts/start.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ createAAR() {
7979
local distDir=$2
8080
local jniLibsDir=$3
8181
local i18n=$4
82+
local headersDir=${distDir}/include
8283
printf "\n\n\t\t===================== create aar :${target}: =====================\n\n"
8384
cd $ROOTDIR/lib
8485
./gradlew clean :${target}:publish \
8586
--project-prop distDir="${distDir}" \
8687
--project-prop jniLibsDir="${jniLibsDir}" \
87-
--project-prop revision="$REVISION" \
88+
--project-prop headersDir="${headersDir}" \
89+
--project-prop version="${npm_package_version}" \
8890
--project-prop i18n="${i18n}"
8991
cd $ROOTDIR
9092
}
@@ -104,19 +106,19 @@ export I18N=true
104106
prep
105107
compile
106108

107-
export DISTDIR=${ROOTDIR}/dist
108109
printf "\n\n\t\t===================== create stripped distributions =====================\n\n"
109-
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
110-
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
111-
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
110+
export DISTDIR=${ROOTDIR}/dist
112111
copyHeaders ${DISTDIR}
112+
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
113+
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
114+
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
113115

114116
printf "\n\n\t\t===================== create unstripped distributions =====================\n\n"
115117
export DISTDIR=${ROOTDIR}/dist.unstripped
116-
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
117-
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"
118-
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
119118
copyHeaders ${DISTDIR}
119+
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
120+
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"
121+
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
120122

121123
npm run info
122124

test/app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"web": {
2727
"favicon": "./assets/favicon.png"
2828
},
29-
"jsEngine": "jsc"
29+
"jsEngine": "jsc",
30+
"plugins": ["./plugins/withJscAndroid"]
3031
}
3132
}

test/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"start": "expo start",
77
"android": "expo run:android",
88
"ios": "expo run:ios",
9-
"web": "expo start --web",
10-
"postinstall": "rm -rf node_modules/jsc-android/dist && cd node_modules/jsc-android && ln -s ../../../dist"
9+
"web": "expo start --web"
1110
},
1211
"dependencies": {
1312
"expo": "~52.0.7",

0 commit comments

Comments
 (0)