+-
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:\projects\veida\veida_v1\Erua3\android\app\src\main\java\com\erua3\MainActivity.java:12: error: cannot find symbol
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                                  ^
  symbol:   class Intent
  location: class MainActivity
1 error

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 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示例。

1
投票

您可以通过在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进行比较。