Skip to content

Commit

Permalink
Override libfbjni.so (#2209)
Browse files Browse the repository at this point in the history
## Description

I added `libfbjni.so` (in version 0.2.2 with dynamic loading of libc++.so) to reanimated aar package. Reanimated will automatically change application configuration and add Gradle option:
```
android {
  ...
  packagingOptions {
    pickFirst 'lib/**/libfbjni.so'
  }
  ...
}
```
To disable this behavior user just need to add to `app/gradle.build` the following config:
```
project.ext.reanimated = [
    enablePackagingOptions: false,
]
```
  • Loading branch information
piaskowyk committed Jul 26, 2021
1 parent 4da7fd7 commit bb62c77
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def enableProguardInReleaseBuilds = false

android {
compileSdkVersion rootProject.ext.compileSdkVersion

configurations {
all*.exclude module: 'fbjni-java-only'
}
defaultConfig {
applicationId "com.swmansion.reanimated.example"
minSdkVersion rootProject.ext.minSdkVersion
Expand Down
2 changes: 1 addition & 1 deletion Example/src/AnimatedStyleUpdateExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ function AnimatedStyleUpdateExample(): React.ReactElement {
);
}

export default AnimatedStyleUpdateExample;
export default AnimatedStyleUpdateExample;
9 changes: 9 additions & 0 deletions android-npm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ def (major, minor, patch) = reactNativeVersion.tokenize('.')

def engine = "jsc"
rootProject.getSubprojects().forEach({project ->
if(project.getProperties().get("android")) {
def projectProperties = project.getProperties()
if(!projectProperties.get("reanimated")
|| (projectProperties.get("reanimated") && projectProperties.get("reanimated").get("enablePackagingOptions"))
) {
project.getProperties().android.packagingOptions.pickFirst("lib/**/libfbjni.so")
}
}

if (project.plugins.hasPlugin("com.android.application")) {
if(project.ext.react.enableHermes) {
engine = "hermes"
Expand Down
16 changes: 3 additions & 13 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ find_library(
LOG_LIB
log
)
find_library(
FBJNI_LIB
fbjni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
HERMES_LIB
hermes
Expand All @@ -117,17 +111,13 @@ find_library(
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
FBJNI_LIBRARY fbjni
PATHS ${libfbjni_link_DIRS}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
GLOG_LIB
glog
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_package(fbjni REQUIRED CONFIG)
# build shared lib

set_target_properties(${PACKAGE_NAME} PROPERTIES LINKER_LANGUAGE CXX)
Expand All @@ -140,7 +130,7 @@ if(${FOR_HERMES})
${LOG_LIB}
${HERMES_LIB}
${GLOG_LIB}
${FBJNI_LIB}
fbjni::fbjni
${FOLLY_JSON_LIB}
${REACT_NATIVE_JNI_LIB}
android
Expand All @@ -151,7 +141,7 @@ else()
${LOG_LIB}
${JSEXECUTOR_LIB}
${GLOG_LIB}
${FBJNI_LIB}
fbjni::fbjni
${FOLLY_JSON_LIB}
${REACT_NATIVE_JNI_LIB}
android
Expand Down
12 changes: 8 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ if(!System.getenv('IS_TRAVIS')) {
}

android {
buildFeatures {
prefab true
}
compileSdkVersion safeExtGet('compileSdkVersion', 29)
buildToolsVersion safeExtGet('buildToolsVersion', '29.0.2')
defaultConfig {
Expand Down Expand Up @@ -131,7 +134,7 @@ android {
packagingOptions {
println "Native libs debug enabled: ${debugNativeLibraries}"
doNotStrip debugNativeLibraries ? "**/**/*.so" : ''
excludes = ["**/libc++_shared.so"]
excludes = REACT_VERSION < 65 ? ["**/libc++_shared.so"] : ["**/libc++_shared.so", "**/libfbjni.so"]
}

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -460,10 +463,11 @@ repositories {

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.facebook.fbjni:fbjni:0.2.2'
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "androidx.transition:transition:1.1.0"
extractHeaders("com.facebook.fbjni:fbjni:0.0.2:headers")
extractSO("com.facebook.fbjni:fbjni:0.0.2")
extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
extractSO("com.facebook.fbjni:fbjni:0.2.2")

def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
def jscAAR = fileTree("${rootDir}/../node_modules/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
Expand Down
2 changes: 2 additions & 0 deletions createNPMPackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ npm pack
mv android android-npm
mv android-temp android

rm -rf ./lib

echo "Done!"

0 comments on commit bb62c77

Please sign in to comment.