android - React-native:任务':app:compileDebugJavawithJavac'的执行失败
问题描述
我对 react-native 和 gradle (一般编码)相对较新。我正在尝试在手机上运行我的代码,但我不断收到以下错误:Execution failed for task ':app:compileDebugJavawithJavac'
.
我曾尝试寻找解决方案,但都没有奏效。我努力了:
重新安装环境变量 JAVA_HOME,
运行 gradlew clean,并且
npm也安装在我的 android 文件夹中,但没有任何效果。
这是我得到的回复:
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:5: error: cannot find symbol
import com.facebook.react.ReactApplication;
^
symbol: class ReactApplication
location: package com.facebook.react
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
^
symbol: class ReactNativeHost
location: package com.facebook.react
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:14: error: cannot find symbol
public class MainApplication extends Application implements ReactApplication {
^
symbol: class ReactApplication
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:36: error: cannot find symbol
public ReactNativeHost getReactNativeHost()
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
public class MainActivity extends ReactActivity {
^
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\Saint\OneDrive\Desktop\Important Stuff\Programming stuff\react\Calendar\android\app\src\main\java\com\Calendar\MainApplication.java:35: 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.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
13 actionable tasks: 1 executed, 12 up-to-date
error 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/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.
谢谢您的帮助!
编辑:这是我的 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
解决方案
推荐阅读
- java - 詹金斯中的杀死/释放管道进程
- dart - 有效的 Dart 用法:清除具有相同值和相同类型的变量
- django-models - 有没有办法通过改变另一个模型的布尔状态来改变一个 django 模型的布尔状态
- python - 是否可以在消息中定义变量并稍后将它们用作函数中的变量?
- linux - Ubuntu - 通过 shell 脚本将用户添加到 samba
- ios - 无法解码 BLE 有效载荷
- php - Scandir 递归到具有多维“数组”的 Json
- python-3.x - 将 csv 文件上传到 s3 存储桶时出错 - com.amazonaws.services.s3.model.AmazonS3Exception:状态代码:400
- kotlin - 如何确保异步测试不会干扰另一个?
- spring-boot - javax.net.ssl.SSLException: SSLEngine 已关闭 SSLEngine 已在 webclient (Springboot) 中关闭