gpt4 book ai didi

java - 任务 ':app:compileDebugJavaWithJavac' 执行失败。在运行 React Native 项目时

转载 作者:搜寻专家 更新时间:2023-11-01 09:23:42 26 4
gpt4 key购买 nike

我在我的真实 Android 设备上运行我现有的 React Native 项目。然后以某种方式弹出此错误。错误总是关于“找不到符号”。我有 JDK 和 SDK 并添加到我的系统变量中。但我仍然不知道为什么它会给我这样的错误。我记得,我只是降级了 react-native 的版本。

:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication; ^ symbol: class ReactApplication location: package com.facebook.react D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:6: error: cannot find symbol import com.facebook.react.ReactNativeHost; ^ symbol: class ReactNativeHost location: package com.facebook.react D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:14: error: cannot find symbol public class MainApplication extends Application implements ReactApplication { ^ symbol: class ReactApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:36: error: cannot find symbol public ReactNativeHost getReactNativeHost() { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity public class MainActivity extends ReactActivity { ^ D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\rnprojects\firstproject\android\app\src\main\java\com\emptyprojecttemplate\MainApplication.java:35: error: method does not override or implement a method from a supertype @Override ^ 8 errors :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

构建.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

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

Build.gradle/应用程序:

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.emptyprojecttemplate"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

最佳答案

您的堆栈跟踪以:error: cannot find symbol import com.facebook.react.ReactApplication 这似乎表明它无法找到 React Library 导入。

我将在 Github 上为您提供一个答案,请阅读此处:

https://github.com/transistorsoft/react-native-background-geolocation/issues/294

(顺便说一句,这与 /your-project/android/build.gradle 中的 build.gradle 相关)

如果其他人遇到同样的问题:请确保您正确添加了新的存储库。根据 Android 文档,每个 Maven 存储库都应位于其自己的 Maven {} block 中。

这就是为什么

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

打破依赖关系。正确的版本是

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

更新

因为上面没有解决你的问题,你的 build.gradle(s) 看起来不错(对我来说)。我将包括一些其他解决方案:

按照此处的建议升级 RN 和 RN-cli:

Cannot resolve symbol ReactApplication/ReactNativeHost

另一个在这里:

FAILURE: Build failed with an exception in react-native Android

另一个在这里:

React native android error: cannot find symbol

不得已

可能值得创建一个新的测试项目(使用最新版本),比如react-native init anotherproject,看看它是否运行。

关于java - 任务 ':app:compileDebugJavaWithJavac' 执行失败。在运行 React Native 项目时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52472658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com