升级到 0.60 后 React-Native 找不到符号 [英] React-Native cannot find symbol after upgrade to 0.60

查看:71
本文介绍了升级到 0.60 后 React-Native 找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的 react-native 应用程序 0.59.4 升级到 0.60.0.

I try to upgrade my react-native app 0.59.4 to 0.60.0.

我使用这个链接 作为升级所有本机文件的参考.但是,当我尝试在 Android 设备上运行我的应用程序时,出现此错误:

I use this link as reference to upgrade all native files. But when I try to run my app on an Android device, I've got this error :

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 4 executed, 8 up-to-date
/home/stephane/Project/youtube-audio-player/android/app/src/main/java/com/youtubeaudioplayer/MainApplication.java:5: error: cannot find symbol
import com.facebook.react.PackageList;
                         ^
  symbol:   class PackageList
  location: package com.facebook.react
/home/stephane/Project/youtube-audio-player/android/app/src/main/java/com/youtubeaudioplayer/MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactApplication;
                         ^
  symbol:   class ReactApplication
  location: package com.facebook.react
/home/stephane/Project/youtube-audio-player/android/app/src/main/java/com/youtubeaudioplayer/MainApplication.java:7: error: cannot find symbol
import com.facebook.react.ReactNativeHost;

有人已经成功升级到 0.60 版本了吗?

Did anyone already upgrade to 0.60 version successfully?

推荐答案

当我从 0.59.10 迁移到 0.60.0 时使用相同的页面时,我实际上错过了一些小事情.

I actually missed a few tiny things when using the same page as you did when I migrated from 0.59.10 to 0.60.0.

我遗漏的一件事(我最终可以查明这是我的案例中的问题)是必须将此部分添加到 /android/app/build.gradle 的底部:

One of the things I missed (which I could pinpoint was the problem in my case eventually) was that this section had to be added in the bottom of /android/app/build.gradle:

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

我在 /android/settings.gradle 中只有类似的一行,但错过了那一行.

I only had the similar line it in /android/settings.gradle but missed that one.

还有其他原因导致这种情况也可能发生.
以下是我在尝试修复项目时发现的 GitHub 问题:

There are other reasons why this might be happening too.
Following are GitHub issues I found while trying to fix my project:

  • https://github.com/facebook/react-native/issues/9296: Clear the IDE caches and restart; didn't apply in my case but might do in yours.
  • https://github.com/facebook/react-native/issues/22033 Two solutions proposed:

  1. 确保 maven { url("$rootDir/../node_modules/react-native/android") } 在你的 allProjects.repositories/android/build.gradle

将您的 react-native 依赖项明确设置为您使用的版本.因此,在 dependencies 部分的 /android/app/build.gradle 中,您应该找到一个条目 compile "com.facebook.react:react-native:+.您可以将其更改为 compile "com.facebook.react:react-native:0.60.0.在某些情况下,gradle 使用旧版本的库,因为它被某些 JavaScript 依赖项引用.此更改应覆盖该更改.

Explicitly set your react-native dependency to the version you use. So in /android/app/build.gradle in the dependencies section, you should find an entry compile "com.facebook.react:react-native:+. You can change that to compile "com.facebook.react:react-native:0.60.0. In some cases gradle used an old version of the library because it was referenced by some JavaScript dependency. This change should override that.

这篇关于升级到 0.60 后 React-Native 找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆