【发布时间】: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.java 和 MainActivity.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