React-Native cannot find symbol after upgrade to 0

2020-08-17 17:30发布

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

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;

Did anyone already upgrade to 0.60 version successfully?

1条回答
Deceive 欺骗
2楼-- · 2020-08-17 18:10

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.

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)

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


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. Make sure maven { url("$rootDir/../node_modules/react-native/android") } is in your allProjects.repositories in /android/build.gradle

    2. 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.

查看更多
登录 后发表回答