当前位置: 首页 > 知识库问答 >
问题:

React本机Android:app:CompiledBugJava错误

尹臻
2023-03-14

当我运行react native run android时,我得到以下错误:;我正在将其设置为在设备上运行。

:app:compileDebugJava
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactApplication;
                         ^
  symbol:   class ReactApplication
  location: package com.facebook.react
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:8: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
                         ^
  symbol:   class ReactNativeHost
  location: package com.facebook.react
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:15: error: cannot find symbol
public class MainApplication extends Application implements ReactApplication {
                                                            ^
  symbol: class ReactApplication
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:17: error: cannot find symbol
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                ^
  symbol:   class ReactNativeHost
  location: class MainApplication
/Users/hello/MediaFire/apps/v/android/app/src/main/java/com/test2/MainApplication.java:32: error: cannot find symbol
  public ReactNativeHost getReactNativeHost() {
         ^
  symbol:   class ReactNativeHost
  location: class MainApplication
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainActivity.java:6: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
public class MainActivity extends ReactActivity {
       ^
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:17: error: cannot find symbol
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                                                       ^
  symbol:   class ReactNativeHost
  location: class MainApplication
/Users/hello/MediaFire/apps/test2/android/app/src/main/java/com/test2/MainApplication.java:31: error: method does not override or implement a method from a supertype
  @Override
  ^
8 errors
:app:compileDebugJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.738 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

共有2个答案

卢枫涟
2023-03-14

检查构建。android中的gradle(项目)文件:

    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }

可能缺少这一行,请将其添加到存储库下,应如下所示:

allprojects {

    repositories {
        mavenLocal()
        jcenter()
        google()


        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

    }
}
白通
2023-03-14

我使用react native upgrade解决了此问题

参考:Overload119的答案

 类似资料: