mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
feat: support Fabric on Android (#1804)
Most of Android changes for Fabric and bump of FabricExample to RN 0.69.2. iOS and JS changes are available in #1821. The most notable change on Android is adding methods to components that accept String values of each NumberProp instead of Dynamic. Another change is changed structure of RenderableViewManager.java since we needed to abstract methods that belong only to components inheriting from VirtualView in order to be able to properly override them in their children.
This commit is contained in:
+84
-2
@@ -14,6 +14,18 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
def isNewArchitectureEnabled() {
|
||||
// To opt-in for the New Architecture, you can either:
|
||||
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
||||
// - Invoke gradle with `-newArchEnabled=true`
|
||||
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
||||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
||||
}
|
||||
|
||||
if (isNewArchitectureEnabled()) {
|
||||
apply plugin: "com.facebook.react"
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
def safeExtGet(prop, fallback) {
|
||||
@@ -23,14 +35,71 @@ def safeExtGet(prop, fallback) {
|
||||
android {
|
||||
compileSdkVersion safeExtGet('compileSdkVersion', 28)
|
||||
|
||||
// Used to override the NDK path/version on internal CI or by allowing
|
||||
// users to customize the NDK path/version from their root project (e.g. for M1 support)
|
||||
if (rootProject.hasProperty("ndkPath")) {
|
||||
ndkPath rootProject.ext.ndkPath
|
||||
}
|
||||
if (rootProject.hasProperty("ndkVersion")) {
|
||||
ndkVersion rootProject.ext.ndkVersion
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion safeExtGet('minSdkVersion', 16)
|
||||
//noinspection OldTargetApi
|
||||
targetSdkVersion safeExtGet('targetSdkVersion', 28)
|
||||
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
||||
if (isNewArchitectureEnabled()) {
|
||||
var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
arguments "APP_PLATFORM=android-21",
|
||||
"APP_STL=c++_shared",
|
||||
"NDK_TOOLCHAIN_VERSION=clang",
|
||||
"GENERATED_SRC_DIR=${appProject.buildDir}/generated/source",
|
||||
"PROJECT_BUILD_DIR=${appProject.buildDir}",
|
||||
"REACT_ANDROID_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid",
|
||||
"REACT_ANDROID_BUILD_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid/build"
|
||||
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
|
||||
cppFlags "-std=c++17"
|
||||
targets "rnsvg_modules"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
if (isNewArchitectureEnabled()) {
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "src/main/jni/Android.mk"
|
||||
}
|
||||
}
|
||||
}
|
||||
packagingOptions {
|
||||
// For some reason gradle only complains about the duplicated version of libreact_render libraries
|
||||
// while there are more libraries copied in intermediates folder of the lib build directory, we exlude
|
||||
// only the ones that make the build fail (ideally we should only include librnscreens_modules but we
|
||||
// are only allowed to specify exlude patterns)
|
||||
exclude "**/libreact_render*.so"
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java {
|
||||
if (isNewArchitectureEnabled()) {
|
||||
srcDirs += [
|
||||
"src/fabric/java",
|
||||
]
|
||||
} else {
|
||||
srcDirs += [
|
||||
"src/paper/java",
|
||||
"build/generated/source/codegen/java"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -44,6 +113,19 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//noinspection GradleDynamicVersion
|
||||
implementation "com.facebook.react:react-native:+"
|
||||
if (isNewArchitectureEnabled()) {
|
||||
implementation project(":ReactAndroid")
|
||||
} else {
|
||||
implementation 'com.facebook.react:react-native:+'
|
||||
}
|
||||
}
|
||||
|
||||
if (isNewArchitectureEnabled()) {
|
||||
react {
|
||||
reactRoot = rootProject.file("../node_modules/react-native/")
|
||||
jsRootDir = file("../src/fabric/")
|
||||
codegenDir = rootProject.file("../node_modules/react-native-codegen/")
|
||||
libraryName = "rnsvg"
|
||||
codegenJavaPackageName = "com.horcrux.rnsvg"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user