react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

[RN 0.70.0-rc.2] newArchEnabled `android/src/main/jni/Android.mk:fb` LOCAL_SRC_FILES points to a missing file

Open leotm opened this issue 1 year ago • 1 comments

react-native-safe-area-context builds fine w newArchEnabled=false but fails w newArchEnabled=true

Context

  • https://github.com/reactwg/react-native-releases/discussions/26#discussioncomment-3327849

Repro

  • https://github.com/leotm/react-native-template-new-architecture/pull/842

Repro (minimal)

  • https://github.com/leotm/RN070RC2

Can also repro locally on macOS 13b

leotm avatar Aug 10 '22 12:08 leotm

I haven't updated to support 0.70 yet, will try to find some time soon

janicduplessis avatar Aug 10 '22 18:08 janicduplessis

Hey, we @software-mansion also encounter this issue with our libs (and in fact this started to break our CI builds since 0.70.0-rc.2). The error originates from a custom Android.mk used for autolinking introduced in this PR by @kmagiera: https://github.com/software-mansion/react-native-screens/pull/1322. Basically, libfb.so does not exist when Android NDK configures the build and that's why it fails.

Fun fact: it works on the second build, because libfb.so has already been built.

To overcome this issue, we decided to use the new autolinking mechanism by @thymikee introduced in 0.70.0-rc.3 and also migrate towards using CMake instead of Android NDK. As a result, we will drop Fabric support for 0.68 and 0.69 in the next release. This already works fine in RNGH (see the PR: https://github.com/software-mansion/react-native-gesture-handler/pull/2153). The CI still fails because we use RNScreens & RNSafeAreaContext in our FabricExample, but without these two it builds successfully.

@janicduplessis When do you plan to migrate RNSafeAreaContext to RN 0.70? Do you think it's possible to drop support for 0.68 and 0.69 and migrate towards autolinking & CMake just as we do? If you don't have free time, I think I can submit a PR analogous to the one in RNGH.

tomekzaw avatar Aug 19 '22 17:08 tomekzaw

Hey @tomekzaw, I'm actually working on upgrading to 0.70 today, for fabric I decided to only support latest RC version so I'm fine with dropping support for 0.68/69.

janicduplessis avatar Aug 19 '22 17:08 janicduplessis

@janicduplessis Any word on the upgrade to 0.70? I'm happy to assist to get it taken care of since this issue is currently blocking our team from using the new architecture.

MLawlz avatar Sep 08 '22 16:09 MLawlz

Sorry about the delay on this, I didn't have time to finish the update when I worked on it. I just pushed the work I got done here https://github.com/th3rdwave/react-native-safe-area-context/tree/update-rn, if I remember correctly iOS works and android is left to finish. Feel free to pick it up as I don't think I will have time to finish this until 1-2 weeks.

janicduplessis avatar Sep 08 '22 16:09 janicduplessis

@janicduplessis I'm using RN 0.70.0 but i still have the issue. Is it normal?

allemanfredi avatar Sep 13 '22 09:09 allemanfredi

If i delete node_modules, android/.gradle and android/app/build and then npm install it compiles but unfortunately the app crashes as soon as it starts

allemanfredi avatar Sep 13 '22 15:09 allemanfredi

Any progress?

ugurdalkiran avatar Sep 16 '22 17:09 ugurdalkiran

@janicduplessis: I managed to fix this by removing the externalNativeBuild blocks in build.gradle, and any instances of SoLoader.loadLibrary("safeareacontext_modules") in the code. 0.70 comes with autolinking so these should be redundant now.

 a/android/build.gradle b/android/build.gradle
index 5be6fdb..0fc4046 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -64,42 +64,15 @@ android {
         versionName "1.0"
         buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

-         if (isNewArchitectureEnabled()) {
-            var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
-            var reactAndroidProject = project(':ReactAndroid')
-            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=${reactAndroidProject.projectDir}",
-                            "REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}"
-                    cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
-                    cppFlags "-std=c++17"
-                    targets "safeareacontext_modules"
-                }
-            }
-        }
-
         ndk {
              abiFilters (*reactNativeArchitectures())
-         }
+        }
     }

     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
diff --git a/android/src/fabric/java/com/th3rdwave/safeareacontext/SafeAreaContextComponentsRegistry.kt b/android/src/fabric/java/com/th3rdwave/safeareacontext/SafeAreaContextComponentsRegistry.kt
index 03d07c1..56e2df0 100644
--- a/android/src/fabric/java/com/th3rdwave/safeareacontext/SafeAreaContextComponentsRegistry.kt
+++ b/android/src/fabric/java/com/th3rdwave/safeareacontext/SafeAreaContextComponentsRegistry.kt
@@ -14,10 +14,6 @@ private constructor(componentFactory: ComponentFactory) {
     fun register(componentFactory: ComponentFactory): SafeAreaContextComponentsRegistry {
       return SafeAreaContextComponentsRegistry(componentFactory)
     }
-
-    init {
-      SoLoader.loadLibrary("safeareacontext_modules")
-    }
   }

   @DoNotStrip private val mHybridData: HybridData
diff --git a/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt b/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt
index 4387f0c..feedf4f 100644
--- a/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt
+++ b/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt
@@ -39,13 +39,6 @@ class SafeAreaContextPackage : TurboReactPackage() {
   }

   override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
-    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
-      // For Fabric, we load c++ native library here, this triggers screen's Fabric
-      // component registration which is necessary in order to avoid asking users
-      // to manually add init calls in their application code.
-      // This should no longer be needed if RN's autolink mechanism has Fabric support
-      SoLoader.loadLibrary("safeareacontext_modules")
-    }
     return listOf<ViewManager<*, *>>(SafeAreaProviderManager(), SafeAreaViewManager())
   }
 }

tido64 avatar Sep 22 '22 15:09 tido64

Fixed in 4.4.0 which supports RN 0.70.0

janicduplessis avatar Sep 28 '22 04:09 janicduplessis

Thanks. @tido64 @janicduplessis 🤩🤩

ugurdalkiran avatar Sep 28 '22 06:09 ugurdalkiran