我对react-native和gradle(相对一般的编码)来说还是比较陌生。我正在尝试在手机上运行代码,但始终出现以下错误:Execution failed for task ':app:compileDebugJavawithJavac'
。
我尝试寻找解决方案,但没有一个起作用。我尝试过:
重新安装环境变量JAVA_HOME ,
运行gradlew clean 和
也没有在我的android文件夹中进行 npm安装,但没有任何效果。
这是我得到的答复:
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"
}
}
}