【问题标题】:React-Native Compile Error: cannot find symbolReact-Native 编译错误:找不到符号
【发布时间】:2021-09-26 00:13:30
【问题描述】:
C:\Users\Alex\testing\firsttry>react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-splash-screen
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Task :app:compileDebugJavaWithJavac
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:5: error: cannot find symbol
import com.facebook.react.ReactApplication;
                         ^
symbol:   class ReactApplication
location: package com.facebook.react
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:9: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
                         ^
  symbol:   class ReactNativeHost
  location: package com.facebook.react
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:17: error: cannot find symbolpublic class MainApplication extends Application implements ReactApplication {
                                                        ^
  symbol: class ReactApplication
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:19: error: cannot find symbol  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                ^
  symbol:   class ReactNativeHost
  location: class MainApplication
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainActivity.java:7: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
       ^
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:19: error: cannot find symbol  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                                                       ^
  symbol:   class ReactNativeHost
  location: class MainApplication
C:\Users\Alex\testing\firsttry\android\app\src\main\java\com\firsttry\MainApplication.java:41: error: method does not override or implement a method from a supertype
 @Override
 ^
8 errors

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

我很确定我没有触及 MainApplication.javaMainActivity.java 中的任何内容 我正在虚拟 Android 手机上运行它。

C:\Users\Alex\testing\firsttry>npm -v 6.4.1

C:\Users\Alex\testing\firsttry>react-native -v 反应原生 cli:2.0.1 反应原生:0.57.1​​

谁能帮我解决这个问题/错误?非常感谢!

更新 1:25/11/2018 (GMT+8)

通过将所有 'compile' 替换为 'implementation' 解决了 WARNING 的问题

错误的更多细节 未解决的依赖关系 ./node_modules/react-native-splash-screen/android/build.gradle

请点击链接查看图片。

react-native-splash-screen/android 的 build.gradle

Android Studio 同步错误

更新 2:我通过转到 Android Studio > Gradle 做了一些事情,取消勾选离线工作

现在我得到了同样的错误,找不到符号,但在 Android Studio 中显示不同的错误。

找不到符号 CMD

Android Studio 找不到符号

app:compileDebugJavaWithJavac 错误的错误

【问题讨论】:

  • 阅读错误信息 Alex。您正在使用 compile 而不是 implementation,并使用 testCompile 而不是 testImplementation
  • @eLi 其实如果你仔细阅读,你会发现你所指的不是错误信息,而是警告。
  • 尝试在 Android Studio 中打开您的 React Native 项目并让它构建。这也将设置ANDROID_HOME 环境变量。然后,关闭服务器并运行react-native run-android
  • 感谢@eLi 的建议。我将所有“编译”更改为“实现”,它解决了过时的警告。
  • 更新 2:我通过转到 Android Studio > Settings > Build, Execution, Deplyoment, Gradle, Untick Offline Work 做了一些事情

标签: react-native


【解决方案1】:

首先:使用yarn或者npm安装所有依赖;

第二:使用下面的代码链接iOS和Android原生代码的原生依赖;

  • react-native 链接

第三:这个错误可能是因为你的RN版本与Android的build.gradle版本不同。当您创建一个 react-native 应用程序时,可能会创建一个 android 应用程序,例如:

android/app/build.gradle

  • 实现“com.facebook.react:react-native:+”

因此,检查您的 node_modules 文件夹,查找 react-native 文件夹并查找带有数字的文件夹,该数字是 react-native 版本。对我来说是 0.64.0 然后更新 android/app/build.gradle:

  • 实现“com.facebook.react:react-native:0.64.0”

就是这样。

【讨论】:

    猜你喜欢
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-13
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 2021-08-04
    相关资源
    最近更新 更多