-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Fabric on React Native 0.72 (#13)
- Loading branch information
Showing
71 changed files
with
5,026 additions
and
6,827 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,56 @@ | ||
import java.nio.file.Paths | ||
|
||
buildscript { | ||
if (project == rootProject) { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath("com.android.tools.build:gradle:7.2.1") | ||
} | ||
ext.safeExtGet = {prop, fallback -> | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
} | ||
|
||
static def findNodeModules(baseDir) { | ||
def basePath = baseDir.toPath().normalize() | ||
// Node's module resolution algorithm searches up to the root directory, | ||
// after which the base path will be null | ||
while (basePath) { | ||
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules") | ||
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native") | ||
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) { | ||
return nodeModulesPath.toString() | ||
} | ||
basePath = basePath.getParent() | ||
repositories { | ||
google() | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
classpath("com.android.tools.build:gradle:7.2.0") | ||
} | ||
throw new GradleException("Unable to locate node_modules") | ||
} | ||
|
||
def isNewArchitectureEnabled() { | ||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
if (isNewArchitectureEnabled()) { | ||
apply plugin: 'com.facebook.react' | ||
} | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
def nodeModules = findNodeModules(projectDir) | ||
|
||
android { | ||
namespace "com.klarna.vectordrawable" | ||
compileSdkVersion safeExtGet('compileSdkVersion', 30) | ||
buildToolsVersion safeExtGet('buildToolsVersion', "30.0.2") | ||
|
||
// 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 | ||
} | ||
compileSdkVersion safeExtGet('compileSdkVersion', 31) | ||
|
||
defaultConfig { | ||
minSdkVersion safeExtGet('minSdkVersion', 18) | ||
targetSdkVersion safeExtGet('targetSdkVersion', 30) | ||
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=${nodeModules}/react-native/ReactAndroid", | ||
"REACT_ANDROID_BUILD_DIR=${nodeModules}/react-native/ReactAndroid/build" | ||
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" | ||
cppFlags "-std=c++17" | ||
targets "vectordrawable_modules" | ||
} | ||
} | ||
} | ||
minSdkVersion safeExtGet('minSdkVersion', 21) | ||
targetSdkVersion safeExtGet('targetSdkVersion', 31) | ||
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) | ||
} | ||
|
||
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) | ||
// See: https://github.com/software-mansion/react-native-screens/blob/main/android/build.gradle#L90 | ||
exclude "**/libreact_render*.so" | ||
} | ||
sourceSets { | ||
main { | ||
if (isNewArchitectureEnabled()) { | ||
java.srcDirs += ['src/fabric/java'] | ||
java.srcDirs += ['src/newarch'] | ||
} else { | ||
java.srcDirs += ['src/paper/java', 'build/generated/source/codegen/java'] | ||
java.srcDirs += ['src/oldarch'] | ||
} | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
repositories { | ||
if (project == rootProject) { | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url "$rootDir/../node_modules/react-native/android" | ||
} | ||
mavenCentral() | ||
google() | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url "$projectDir/../node_modules/react-native/android" | ||
} | ||
mavenCentral() | ||
google() | ||
} | ||
|
||
dependencies { | ||
//noinspection GradleDynamicVersion | ||
implementation "com.facebook.react:react-native:+" | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
} | ||
|
||
if (isNewArchitectureEnabled()) { | ||
react { | ||
jsRootDir = file("../src/") | ||
libraryName = "vectordrawable" | ||
codegenJavaPackageName = "com.klarna" | ||
reactNativeDir = rootProject.file("../node_modules/react-native/") | ||
codegenDir = rootProject.file("../node_modules/react-native-codegen/") | ||
} | ||
implementation 'com.facebook.react:react-native:+' | ||
} |
28 changes: 0 additions & 28 deletions
28
android/src/fabric/java/com/klarna/vectordrawable/VectorDrawableComponentsRegistry.java
This file was deleted.
Oops, something went wrong.
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
24 changes: 9 additions & 15 deletions
24
android/src/main/java/com/klarna/vectordrawable/VectorDrawablePackage.java
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 |
---|---|---|
@@ -1,32 +1,26 @@ | ||
package com.klarna.vectordrawable; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.soloader.SoLoader; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("unused") | ||
public class VectorDrawablePackage implements ReactPackage { | ||
|
||
@Override | ||
@NonNull | ||
public List<NativeModule> createNativeModules(@NonNull final ReactApplicationContext reactContext) { | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// TODO: Remove when auto-linking will support Fabric modules | ||
// See: https://github.com/software-mansion/react-native-screens/blob/main/android/src/main/java/com/swmansion/rnscreens/RNScreensPackage.kt#L16 | ||
SoLoader.loadLibrary("vectordrawable_modules"); | ||
} | ||
return Collections.emptyList(); | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
List<ViewManager> viewManagers = new ArrayList<>(); | ||
viewManagers.add(new VectorDrawableManager(reactContext)); | ||
return viewManagers; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public List<ViewManager> createViewManagers(@NonNull final ReactApplicationContext reactContext) { | ||
return Collections.singletonList(new VectorDrawableManager(reactContext)); | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
BUNDLE_PATH: "vendor/bundle" | ||
BUNDLE_FORCE_RUBY_PLATFORM: 1 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.