react-native run-android失败,出现“Task(app:compileDebugJavaWithJavac FAILED”安装后的react-native-fbsdk)

【react-native run-android失败,出现“Task(app:compileDebugJavaWithJavac FAILED”安装后的react-native-fbsdk)】行是知之始,知是行之成。这篇文章主要讲述react-native run-android失败,出现“Task:app:compileDebugJavaWithJavac FAILED”安装后的react-native-fbsdk相关的知识,希望能为你提供帮助。
按照react-native-fbsdk的安装说明操作后,命令react-native run-android失败并出现以下错误:

info JS server already running. info Building and installing the app on the device (cd android & & gradlew.bat app:installDebug)...> Task :app:compileDebugjavaWithJavac FAILED C:projectsveidaveida_v1Erua3androidappsrcmainjavacomerua3MainActivity.java:12: error: cannot find symbol public void onActivityResult(int requestCode, int resultCode, Intent data) { ^ symbol:class Intent location: class MainActivity 1 errorFAILURE: 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.orgBUILD FAILED in 4s 24 actionable tasks: 1 executed, 23 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.

我尝试重新安装android studio并按照两个新项目执行两次安装步骤。
我的App.js是默认的App.js.我也尝试过使用facebook登录的App.js示例。
答案您可以通过在MainActivity.java中添加导入来修复它:
import android.content.Intent;

此外,当您的sdk版本与react-native-fbsdk版本不同时,此错误主要发生。例如:假设你的build.gradle中的SDK版本是:
buildscript { ext { buildToolsVersion = "27.0.3" minSdkVersion = 19 compileSdkVersion = 27 targetSdkVersion = 27 supportLibVersion = "27.0.0" } repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.0.1' } }

但是你的react-native-fbsdk却有所不同
因此,您需要检查是否使用相同的sdk版本。
转到node_modules / react-native-fbsdk / android / build.gradle并将版本与项目build.gradle进行比较。

    推荐阅读