react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

react-native 0.73.2 project getting com.appName.mainActivity can not be cast to com.reactnativenavigation.NavigationActivity

Open Martyneris opened this issue 1 year ago • 13 comments

What happened?

I've installed the latest (7.37.2) version of react-native-navigation in my 0.73.2 react-native project, Android version builds but upon running the project I get the com.appName.mainActivity can not be cast to com.reactnativenavigation.NavigationActivity error. I want to emphasize that with the new 0.73.2 react-native version files I wasn't able to fully follow through with your installation. In react-native 0.73.2 MainActivity.java and MainApplication.java files are replaced with MainActivity.kt and MainApplication.kt respectively and they do not include any of the code that is described in react-native-navigation's installation guide, therefore I didn't know where or what to add.

What was the expected behaviour?

The project runs without any errors

Was it tested on latest react-native-navigation?

  • [X] I have tested this issue on the latest react-native-navigation release and it still reproduces.

Help us reproduce this issue!

No response

In what environment did this happen?

React Native Navigation version: 7.37.2 React Native version: 0.73.2 Has Fabric (React Native's new rendering system) enabled: no Node version: 18.18.0 Device model: Emulator Android version: 14

Martyneris avatar Jan 31 '24 13:01 Martyneris

@Martyneris can you please try the latest version? 7.38.0

asafkorem avatar Feb 18 '24 20:02 asafkorem

Getting the same error 'com.lanch.MainActivity cannot be cast to com.reactnativenavigation.NavigationActivity' in 7.38.3

@asafkorem

aneena-thomas avatar Feb 29 '24 05:02 aneena-thomas

same issue

ombogdanJoinToIt avatar Feb 29 '24 13:02 ombogdanJoinToIt

Switching to .java fixed issues for me

aneena-thomas avatar Feb 29 '24 13:02 aneena-thomas

@aneena-thomas do you have error in ios?

ombogdanJoinToIt avatar Feb 29 '24 13:02 ombogdanJoinToIt

No errors. Keep the old MainActivity.java and MainApplication.java as it is.

aneena-thomas avatar Feb 29 '24 13:02 aneena-thomas

@aneena-thomas I get errors on iOS

ombogdanJoinToIt avatar Feb 29 '24 14:02 ombogdanJoinToIt

What are the errors you got? @ombogdanJoinToIt

aneena-thomas avatar Feb 29 '24 14:02 aneena-thomas

I think this error does not belong to this thread @aneena-thomas Error: Component "myProjectID" does not have a componentId!

This error is located at: in WrappedComponent in RCTView in Unknown in RCTView in Unknown in AppContainer, js engine: hermes

ombogdanJoinToIt avatar Feb 29 '24 14:02 ombogdanJoinToIt

This one is working for me:

package xx.xxx.xx

import com.facebook.react.ReactActivityDelegate
import com.reactnativenavigation.NavigationActivity
import com.facebook.react.ReactRootView
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled

class MainActivity : NavigationActivity() {
    class MainActivityDelegate(activity: NavigationActivity?, mainComponentName: String?) :
        ReactActivityDelegate(activity, mainComponentName) {

        override fun createRootView(): ReactRootView {
            val reactRootView = ReactRootView(context)
            // If you opted-in for the New Architecture, we enable the Fabric Renderer.
            reactRootView.setIsFabric(fabricEnabled)
            return reactRootView
        }
    }
}

rashidul0405 avatar Jun 23 '24 13:06 rashidul0405

I am experiencing the same problem. @rashidul0405 Can you elaborate a bit more how you solved it?

lucasahlgrenToxic avatar Jul 30 '24 09:07 lucasahlgrenToxic

I am experiencing the same problem. @rashidul0405 Can you elaborate a bit more how you solved it?

This is MainActivity.kt. What else do you need?

rashidul0405 avatar Aug 03 '24 09:08 rashidul0405

I am experiencing the same problem. @rashidul0405 Can you elaborate a bit more how you solved it?

This is MainActivity.kt. What else do you need?

I was able to get it to work in the end. Thanks anyway.

lucasahlgrenToxic avatar Aug 05 '24 10:08 lucasahlgrenToxic