m4gr3d / Godot-Android-Samples

Collection of Godot Android plugins
MIT License
43 stars 6 forks source link

java.lang.IllegalStateException: Unable to initialize engine native layer at org.godotengine.godot.GodotFragment #12

Open kyadalu1 opened 12 months ago

kyadalu1 commented 12 months ago

I am trying to embed GodotView in my react-native app for android. I am following this documentation over here which allows react-nativeto embed any native view from android

I get the following error when i run my app

2023-12-08 10:29:49.675 12977-12977 AndroidRuntime          com.rnapp                            E  FATAL EXCEPTION: main
                                                                                                    Process: com.rnapp, PID: 12977
                                                                                                    java.lang.IllegalStateException: Unable to initialize engine native layer
                                                                                                        at org.godotengine.godot.GodotFragment.performEngineInitialization(GodotFragment.java:191)
                                                                                                        at org.godotengine.godot.GodotFragment.onCreate(GodotFragment.java:182)
                                                                                                        at androidx.fragment.app.Fragment.performCreate(Fragment.java:2949)
                                                                                                        at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:475)
                                                                                                        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
                                                                                                        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
                                                                                                        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
                                                                                                        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
                                                                                                        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                        at android.os.Looper.loop(Looper.java:313)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8669)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Here is the complete repo for my app

Here is a quick gist of my code

There is a folder called RTNQrCode which has my Godot project in the assets folder. It is not in the main android folder. Just to give you a context in react-native typically we create a separate npm module to embed the view in react native's new architecture. The react-native docs does not specified how to create a fabric component in the main android folder as of yet. I am ignoring the old architecture of react native as that will soon be removed.

Here is the gist code

class QrCode(context: Context) : LinearLayout(context) {

    private val frameLayout: FrameLayout

    init {
        layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        frameLayout = FrameLayout(context)
        frameLayout.id = View.generateViewId()

        addView(frameLayout)

        frameLayout.apply {
            frameLayout.layoutParams.height = 300

            val fragmentTransaction = ((context as ReactContext).currentActivity as AppCompatActivity).supportFragmentManager.beginTransaction()
            fragmentTransaction.replace(frameLayout.id, GodotFragment())
            fragmentTransaction.commit()
        }
    }

}