0

I've just updated React Native from 0.71.11 to 0.73.7 following the instructions from the React Native upgrade helper. When I try to run 'yarn android', I get this error

error: android/app/src/main/java/com/useapp/MainApplication.kt:18:41 Return type of 'getPackages' is not a subtype of the return type of the overridden member 'protected/protected and package/ abstract fun getPackages(): (MutableList<ReactPackage!>..kotlin.collections.List<ReactPackage!>?) defined in com.facebook.react.defaults.DefaultReactNativeHost' e: /android/app/src/main/java/com/useapp/MainApplication.kt:19:24 Type mismatch: inferred type is ArrayList<ReactPackage!>! but List was expected e: android/app/src/main/java/com/useapp/MainApplication.kt:35:13 Unresolved reference: ReactHost

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

MainApplication.kt

package xxx.xxx

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
import java.util.List
import com.vinzscam.reactnativefileviewer.RNFileViewerPackage
import com.oblador.vectoricons.VectorIconsPackage

class MainApplication : Application(), ReactApplication {

    override val reactNativeHost: ReactNativeHost =
        object : DefaultReactNativeHost(this) {
            override fun getPackages(): List<ReactPackage> {
                return PackageList(this).packages // Use PackageList to get packages
            }

            override fun getJSMainModuleName(): String = "index"

            override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

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

    override fun onCreate() {
        super.onCreate()
        SoLoader.init(this, false)
        if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
            // If you opted-in for the New Architecture, we load the native entry point for this app.
            ReactHost.load() // This seems to be a custom function, make sure it's defined correctly
        }
        // ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
        // This line is commented out as ReactNativeFlipper seems unresolved in your code
    }
}

MainActivity.kt

package xxx.xxx
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultReactActivityDelegate
import android.os.Bundle

class MainActivity : ReactActivity() {

    /**
     * Returns the name of the main component registered from JavaScript. This is used to schedule
     * rendering of the component.
     */
    override fun getMainComponentName(): String = "xxx"

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

    /**
     * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
     * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
     */
    override fun createReactActivityDelegate(): ReactActivityDelegate =
        DefaultReactActivityDelegate(this, "useapp") // Provide mainComponentName as a string
}

I've tried to mess with both files, but so far without success.

1
  • one thing you can try, build new project with latest version of react native then move your previous javascript code to this project and also install packages manually rather older version then try to rebuild. hope this work for you Commented Apr 25, 2024 at 4:23

1 Answer 1

0

just remove

import java.util.List

in your MainApplication.kt and try again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.