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

null cannot be cast to non-null type com.reactnativenavigation.NavigationActivity

Open AleshkovDenis opened this issue 7 months ago • 2 comments

What happened?

How can I fix it?

Image

What was the expected behaviour?

No response

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!

MainAcitivity.kt

package com.app;

import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled;
import com.facebook.react.defaults.DefaultReactActivityDelegate;

class MainActivity:NavigationActivity() {}

MainApplication.kt

package com.app

import com.facebook.react.PackageList
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.reactnativenavigation.NavigationApplication
import com.reactnativenavigation.react.NavigationPackage
import com.reactnativenavigation.react.NavigationReactNativeHost
import com.microsoft.codepush.react.CodePush

class MainApplication : NavigationApplication() {
  override val reactNativeHost: ReactNativeHost =
      object : NavigationReactNativeHost(this) {
        override fun getPackages(): List<ReactPackage> =
            PackageList(this).packages.apply {
              // Packages that cannot be autolinked yet can be added manually here, for example:
              // add(MyReactNativePackage())
            }

        override fun getJSMainModuleName(): String = "index"

        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

        override fun getJSBundleFile(): String {
          return CodePush.getJSBundleFile() 
        }

        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
      }

      override val reactHost: ReactHost
          get() = getDefaultReactHost(this, reactNativeHost)

  override fun onCreate() {
    super.onCreate()
  }
}

In what environment did this happen?

React Native Navigation version: 8.1.0 React Native version: 0.77.2 Has Fabric (React Native's new rendering system) enabled: yes Node version: 20 Device model: Samsung Galaxy Tab A9 + (emulator) Android version: 15

AleshkovDenis avatar Jun 17 '25 10:06 AleshkovDenis

Hey @AleshkovDenis,

did you try to add RNNotificationsPackage in getPackages?

 override fun getPackages(): List<ReactPackage> =
                        PackageList(this).packages.apply {
                            add(NavigationPackage()) // <-- 
                        }

Android works for me with this MainApplication.kt

package ...

import com.facebook.react.PackageList
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.reactnativenavigation.NavigationApplication
import com.reactnativenavigation.RNNToggles
import com.reactnativenavigation.react.NavigationPackage
import com.reactnativenavigation.react.NavigationReactNativeHost
import com.wix.reactnativenotifications.RNNotificationsPackage;

class MainApplication :
        NavigationApplication(
                mapOf(
                        RNNToggles.TOP_BAR_COLOR_ANIMATION__PUSH to true,
                        RNNToggles.TOP_BAR_COLOR_ANIMATION__TABS to true
                ) 
        ) {

    override val reactNativeHost: ReactNativeHost =
            object : NavigationReactNativeHost(this) {

                override fun getJSMainModuleName(): String = "index"

                override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

                override fun getPackages(): List<ReactPackage> =
                        PackageList(this).packages.apply {
                            add(NavigationPackage())
                        }

                override val isHermesEnabled: Boolean
                    get() = BuildConfig.IS_HERMES_ENABLED

                override val isNewArchEnabled: Boolean
                    get() = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
            }

    override val reactHost: ReactHost
        get() = getDefaultReactHost(this, reactNativeHost)

    override fun onCreate() {
        super.onCreate()
    }
}


and this MainActivity.kt:

package ...

import android.os.Bundle
import com.reactnativenavigation.NavigationActivity

class MainActivity : NavigationActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
  }
}

ortweinl avatar Jun 17 '25 11:06 ortweinl

@ortweinl it didn't help

AleshkovDenis avatar Jun 17 '25 11:06 AleshkovDenis

resolved

AleshkovDenis avatar Jun 20 '25 07:06 AleshkovDenis

@AleshkovDenis How did you solve it? I have the same issue.

danilomsou avatar Jun 30 '25 10:06 danilomsou