任务“:app:compileDebugKotlin”执行失败。反应本机更新

问题描述 投票:0回答:1

我刚刚按照 React Native 升级助手的说明将 React Native 从 0.71.11 更新到 0.73.7。当我尝试运行“yarn android”时,出现此错误

错误:android/app/src/main/java/com/useapp/MainApplication.kt:18:41“getPackages”的返回类型不是重写成员“protected/protected 和 package”的返回类型的子类型/ Abstract fun getPackages(): (MutableList..kotlin.collections.List?) 在 com.facebook.react.defaults.DefaultReactNativeHost' 中定义 e: /android/app/src/main/java/com/useapp/MainApplication.kt:19:24 类型不匹配:推断类型是 ArrayList!但列表是预期的 e: android/app/src/main/java/com/useapp/MainApplication.kt:35:13 未解析的参考:ReactHost

失败:构建失败并出现异常。

  • 出了什么问题: 任务“:app:compileDebugKotlin”执行失败。

执行 org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction 时发生故障 编译错误。查看日志了解更多详情

主应用程序.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
}

我试图弄乱这两个文件,但到目前为止还没有成功。

android react-native kotlin
1个回答
0
投票

只需删除

导入java.util.List

在您的 MainApplication.kt 中,然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.