forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Add @shopify/react-native-skia vendoring support for Expo Go (
expo#17964) # Why like expo#17704 but for android close ENG-4889 # How - introduce vendor modules autolinking for expo go. previously, reanimated is the only vendor module having cxx code, we had a fixed versioning script for reanimated. because react-native-skia also has cxx code, i'm trying to keep the versioning more modularized and like what we did for ios versioning. ideally, a vendor module should have a dedicated gradle project. that's why i introduced a vendor module autolinking here. - vendoring tool: add react-native-skia support - versioning tool: trying to add a minimum support for new style versioning like ios. currently, after transforming the code, i still prebuild the *.so to `jniLibs`. in the future when we commit `android/versioned-react-native/ABI46_0_0` to git, we can always build the versioned *.so from source. # Test Plan - android unversioned expo go + NCL skia - android versioned expo go + NCL skia Co-authored-by: Tomasz Sapeta <[email protected]>
- Loading branch information
Showing
17 changed files
with
615 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.nio.file.Paths | ||
|
||
|
||
def normalizeProjectName(String projectRoot) { | ||
return projectRoot.replace('/', '_') | ||
} | ||
|
||
/** | ||
* Link vendored modules into settings.gradle | ||
*/ | ||
ext.useVendoredModulesForSettingsGradle = { String sdkVersion -> | ||
def vendoredRoot = Paths.get(rootDir.toString(), 'vendored', sdkVersion).toString() | ||
fileTree(dir: vendoredRoot, include: '**/build.gradle').each { gradleFile -> | ||
def projectRoot = rootDir.toPath().relativize(gradleFile.toPath()).getParent().getParent().toString() | ||
def projectName = normalizeProjectName(projectRoot) | ||
|
||
include(":${projectName}") | ||
project(":${projectName}").projectDir = gradleFile.getParentFile() | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Link vendored modules into settings.gradle | ||
*/ | ||
ext.useVendoredModulesForExpoView = { String sdkVersion -> | ||
def vendoredRoot = Paths.get(rootDir.toString(), 'vendored', sdkVersion).toString() | ||
fileTree(dir: vendoredRoot, include: '**/build.gradle').each { gradleFile -> | ||
def projectRoot = rootDir.toPath().relativize(gradleFile.toPath()).getParent().getParent().toString() | ||
def projectName = normalizeProjectName(projectRoot) | ||
|
||
dependencies.add('implementation', project(":${projectName}")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
--- android/CMakeLists.txt | ||
+++ android/CMakeLists.txt | ||
@@ -34,14 +34,14 @@ add_library( | ||
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkDrawViewImpl.cpp" | ||
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLRenderer.cpp" | ||
|
||
- "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp" | ||
+ "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp" | ||
|
||
- "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp" | ||
- "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDrawView.cpp" | ||
- "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDispatchQueue.cpp" | ||
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp" | ||
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDrawView.cpp" | ||
+ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDispatchQueue.cpp" | ||
|
||
|
||
- "${PROJECT_SOURCE_DIR}/cpp/api/third_party/CSSColorParser.cpp" | ||
+ "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp" | ||
|
||
) | ||
|
||
@@ -56,28 +56,28 @@ target_include_directories( | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core" | ||
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni" | ||
|
||
- cpp/skia/include/config/ | ||
- cpp/skia/include/core/ | ||
- cpp/skia/include/effects/ | ||
- cpp/skia/include/utils/ | ||
- cpp/skia/include/pathops/ | ||
- cpp/skia/modules/ | ||
- cpp/skia/include/ | ||
- cpp/skia | ||
- | ||
- cpp/api | ||
- cpp/jsi | ||
- cpp/jni/include | ||
- cpp/rnskia-android | ||
- cpp/rnskia | ||
- cpp/rnskia/values | ||
- cpp/utils | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/config/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/core/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/effects/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/utils/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/pathops/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/modules/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia/include/ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/skia | ||
+ | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/api | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/jsi | ||
+ ${PROJECT_SOURCE_DIR}/cpp/jni/include | ||
+ ${PROJECT_SOURCE_DIR}/cpp/rnskia-android | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/rnskia | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/rnskia/values | ||
+ ${PROJECT_SOURCE_DIR}/../cpp/utils | ||
|
||
${libfbjni_include_DIRS} | ||
) | ||
|
||
# Import prebuilt SKIA libraries | ||
-set (SKIA_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}") | ||
+set (SKIA_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/libs/${ANDROID_ABI}") | ||
add_library(skia STATIC IMPORTED) | ||
set_property(TARGET skia PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskia.a") | ||
|
||
--- android/build.gradle | ||
+++ android/build.gradle | ||
@@ -43,13 +43,17 @@ static def findNodeModules(baseDir) { | ||
throw new GradleException("React-Native-Skia: Failed to find node_modules/ path!") | ||
} | ||
|
||
-def nodeModules = findNodeModules(projectDir) | ||
+def nodeModules = Paths.get(projectDir.getPath(), '../../../../../..', 'react-native-lab').toString() | ||
logger.warn("react-native-skia: node_modules/ found at: ${nodeModules}") | ||
|
||
def sourceBuild = false | ||
def defaultDir = null | ||
def androidSourcesDir = null | ||
def androidSourcesName = 'React Native sources' | ||
+def reactNativeArchitectures() { | ||
+ def value = project.getProperties().get("reactNativeArchitectures") | ||
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] | ||
+} | ||
|
||
def buildType = "debug" | ||
tasks.all({ task -> | ||
@@ -77,7 +81,7 @@ if (!defaultDir.exists()) { | ||
} | ||
|
||
def prebuiltDir = sourceBuild | ||
- ? "$nodeModules/react-native/ReactAndroid/src/main/jni/prebuilt/lib" | ||
+ ? Paths.get(findProject(":ReactAndroid").getProjectDir().toString(), "build", "intermediates", "library_*", "*", "jni") | ||
: "$buildDir/react-native-0*/jni" | ||
|
||
|
||
@@ -119,7 +123,7 @@ android { | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID" | ||
- abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' | ||
+ abiFilters (*reactNativeArchitectures()) | ||
arguments '-DANDROID_STL=c++_shared', | ||
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}", | ||
"-DNODE_MODULES_DIR=${nodeModules}", | ||
@@ -189,8 +193,10 @@ dependencies { | ||
} else { | ||
// React Native >= 0.69 | ||
def rnAarMatcher = "**/react-native/**/*${buildType}.aar" | ||
- def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile | ||
- extractJNI(files(rnAAR)) | ||
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }) | ||
+ if (rnAAR.any()) { | ||
+ extractJNI(files(rnAAR)) | ||
+ } | ||
} | ||
} | ||
|
||
@@ -255,4 +261,16 @@ def nativeBuildDependsOn(dependsOnTask, variant) { | ||
afterEvaluate { | ||
nativeBuildDependsOn(extractAARHeaders, null) | ||
nativeBuildDependsOn(extractJNIFiles, null) | ||
-} | ||
\ No newline at end of file | ||
+} | ||
+ | ||
+tasks.whenTaskAdded { task -> | ||
+ if (!task.name.contains("Clean") && (task.name.contains('externalNativeBuild') || task.name.startsWith('configureCMake'))) { | ||
+ if (sourceBuild) { | ||
+ def currentBuildType = task.name.endsWith('Debug') ? 'Debug' : 'Release' | ||
+ task.dependsOn(":ReactAndroid:copy${currentBuildType}JniLibsProjectOnly") | ||
+ } | ||
+ } else if (task.name.startsWith('generateJsonModel') && sourceBuild) { | ||
+ def currentBuildType = task.name.endsWith('Debug') ? 'Debug' : 'Release' | ||
+ task.dependsOn(":ReactAndroid:copy${currentBuildType}JniLibsProjectOnly") | ||
+ } | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.