Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: publish rnskia prefab to allow RN Skia to be used in third party libraries #1365

Merged
merged 6 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/getting-started/bundle-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _On *Android* you should use [App Bundles](https://developer.android.com/guide/a

When building an APK in release mode, you will see an increase of 41.3 MB after adding React Native Skia.
This is because the library is built for different target architectures.
If we take `arm-64-bit` for instance, the `libreactskia.so` library file is only around 3,8 MB.
If we take `arm-64-bit` for instance, the `librnskia.so` library file is only around 3,8 MB.

This implies that if you distribute your apps using [App Bundles](https://developer.android.com/guide/app-bundle), the increase in download size should be around 4 MB on Android devices when distributed (including an increase of 220 KB to the Javascript Bundle).

Expand Down
10 changes: 5 additions & 5 deletions package/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_GL -DSK_BUILD_FOR_ANDROID -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")

set (PACKAGE_NAME "reactskia")
set (PACKAGE_NAME "rnskia")
set (SKIA_LIB "skia")
set (SKIA_SVG_LIB "svg")
set (SKIA_SKSHAPER_LIB "skshaper")
Expand All @@ -31,7 +31,7 @@ link_directories(../libs/android/${ANDROID_ABI}/)

if(${REACT_NATIVE_VERSION} LESS 66)
file(
TO_CMAKE_PATH
TO_CMAKE_PATH
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
INCLUDE_JSI_CPP
)
Expand Down Expand Up @@ -59,7 +59,7 @@ add_library(
"${PROJECT_SOURCE_DIR}/cpp/rnskia/dom/base/ConcatablePaint.cpp"

"${PROJECT_SOURCE_DIR}/cpp/api/third_party/CSSColorParser.cpp"

)

target_include_directories(
Expand Down Expand Up @@ -92,7 +92,7 @@ target_include_directories(
cpp/rnskia/dom/base
cpp/rnskia/dom/nodes
cpp/rnskia/dom/props
cpp/utils
cpp/utils

${libfbjni_include_DIRS}
)
Expand Down Expand Up @@ -205,4 +205,4 @@ target_link_libraries(
-lGLESv2
-lEGL
-landroid
)
)
33 changes: 26 additions & 7 deletions package/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ def reactProperties = new Properties()
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
def FULL_RN_VERSION = (System.getenv("REACT_NATIVE_OVERRIDE_VERSION") ?: reactProperties.getProperty("VERSION_NAME"))
def REACT_NATIVE_VERSION = FULL_RN_VERSION.split("\\.")[1].toInteger()
def ENABLE_PREFAB = REACT_NATIVE_VERSION > 68

logger.warn("react-native-skia: RN Version: ${REACT_NATIVE_VERSION} / ${FULL_RN_VERSION}")
logger.warn("react-native-skia: isSourceBuild: ${sourceBuild}")
logger.warn("react-native-skia: PrebuiltDir: ${prebuiltDir}")
logger.warn("react-native-skia: buildType: ${buildType}")
logger.warn("react-native-skia: buildDir: ${buildDir}")
logger.warn("react-native-skia: node_modules: ${nodeModules}")
logger.warn("react-native-skia: Enable Prefab: ${ENABLE_PREFAB}")

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
Expand Down Expand Up @@ -132,14 +134,10 @@ android {

externalNativeBuild {
cmake {
path file('CMakeLists.txt')
path file('CMakeLists.txt')
}
}

buildFeatures {
prefab true
}

packagingOptions {
excludes = [
"**/libc++_shared.so",
Expand All @@ -150,6 +148,18 @@ android {
]
}

if (ENABLE_PREFAB) {
buildFeatures {
prefab true
prefabPublishing true
}
prefab {
rnskia {
headers "${project.buildDir}/headers/rnskia/"
}
}
}

// Create new configurations that can be referred to in dependencies.
// The Android Gradle Plugin 3.* does not allow hooking into existing
// configurations like `implementation`.
Expand Down Expand Up @@ -255,6 +265,15 @@ task extractJNIFiles {

extractJNIFiles.mustRunAfter extractAARHeaders

if (ENABLE_PREFAB) {
task prepareHeaders(type: Copy) {
from fileTree('../cpp').filter { it.isFile() }
into "${project.buildDir}/headers/rnskia/"
includeEmptyDirs = false
}
preBuild.dependsOn(prepareHeaders)
}

def nativeBuildDependsOn(dependsOnTask, variant) {
def buildTasks = tasks.findAll({ task ->
!task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) })
Expand All @@ -266,5 +285,5 @@ def nativeBuildDependsOn(dependsOnTask, variant) {

afterEvaluate {
nativeBuildDependsOn(extractAARHeaders, null)
nativeBuildDependsOn(extractJNIFiles, null)
}
nativeBuildDependsOn(extractJNIFiles, null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean install() {
}

try {
System.loadLibrary("reactskia");
System.loadLibrary("rnskia");
ReactApplicationContext context = weakReactContext.get();
if (context == null) {
Log.e(NAME, "React Application Context was null!");
Expand Down