-
I'm currently in the process of making some remaining internal packages compatible with the New Architecture through the Interop Layer. Unfortunately, I keep running into an issue with
Source code and gradle setupThis is a minified excerpt from one of the affected Kotlin modules:package com.somecompany.someapp
import android.Manifest
import android.content.pm.PackageManager
import android.util.Log
import android.os.Bundle
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule
class SomeAppModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName(): String {
return NAME
}
private fun sendEvent(eventName: String, params: Any?) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit(eventName, params)
}
@ReactMethod
fun someMethod(options: ReadableMap, promise: Promise) {
val currentActivity = currentActivity
if (currentActivity == null) {
promise.reject("ERROR", "Activity is null")
return
}
try {
// Run on main thread
UiThreadUtil.runOnUiThread {
try {
// ... do some stuff on the UI thread
sendEvent("RNSomeApp.event", "some data")
} catch (e: Exception) {
promise.reject("ERROR", "Some error... ${e.message}")
}
}
} catch (e: Exception) {
promise.reject("ERROR", "Some error... ${e.message}")
}
}
companion object {
const val NAME = "SomeApp"
}
} This is the module's build.gradle:
And its gradle.properties:
This is the app's build.gradle:
It works fine when disabling the New Architecture and building without it. I'm unable to find any related issue to this or any material saying that we need to migrate While I'm aware that the documentation on Native Modules isn't fully updated for the New Architecture yet, this does make me wonder that I seem to be the only person encountering this issue – leading me to believe that it's some problem in my build set-up? Can someone help with this? Update 1: This seems to be limited to React Native 0.76. After downgrading everything back to 0.75 (according to the RN Update Helper), the build and the module itself work fine, even with New Architecture enabled. Therefore not sure if this is fitting as a discussion here in the WG, or if it's more fitting as a bug report in React Native itself. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Pretty sure this is an issue with |
Beta Was this translation helpful? Give feedback.
Pretty sure this is an issue with
create-react-native-library
since I can't reproduce it when setting up a native module myself without this helper tool. Closing this since probably unrelated.