安装react-native-fbsdk后,react-native run-android失败,并出现“任务:app:compileDebugJavaWithJavac FAILED”

时间:2019-04-10 09:07:09

标签: android facebook react-native react-native-fbsdk

按照react-native-fbsdk的安装说明进行操作后,命令     react-native运行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。我还尝试将示例App.js与Facebook登录名一起使用。

2 个答案:

答案 0 :(得分: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版本。

答案 1 :(得分:0)

尝试

我如何解决此问题:

首先,请确保已设置%java_home%变量,并且还确保%path%包含了Java sdk。 How to setup Java environment variables

第二,转到您的android文件夹并运行以下命令:

C:\Projects\myproject\android>gradlew.bat app:installDebug.
  

解压缩   C:\ Users \ codeb.gradle \ wrapper \ dists \ gradle-4.10.2-all \ 9fahxiiecdb76a5g3aw9oi8rv \ gradle-4.10.2-all.zip   至   C:\ Users \ codeb.gradle \ wrapper \ dists \ gradle-4.10.2-all \ 9fahxiiecdb76a5g3aw9oi8rv   线程“主”中的异常java.util.zip.ZipException:错误   打开压缩文件           在java.util.zip.ZipFile.open(本机方法)           在java.util.zip.ZipFile。(ZipFile.java:225)           在java.util.zip.ZipFile。(ZipFile.java:155)           在java.util.zip.ZipFile。(ZipFile.java:169)           在org.gradle.wrapper.Install.unzip(Install.java:215)           在org.gradle.wrapper.Install.access $ 600(Install.java:27)           在org.gradle.wrapper.Install $ 1.call(Install.java:75)           在org.gradle.wrapper.Install $ 1.call(Install.java:48)           在org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)           在org.gradle.wrapper.Install.createDist(Install.java:48)           在org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)           在org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

您可以看到我的gradle下载已损坏。您所要做的就是删除此文件夹,然后重新运行命令。

C:\Projects\myproject\android>gradlew.bat app:installDebug
  

下载   https://services.gradle.org/distributions/gradle-4.10.2-all.zip   ................................................... ................................................... ...........   解压缩   C:\ Users \ codeb.gradle \ wrapper \ dists \ gradle-4.10.2-all \ 9fahxiiecdb76a5g3aw9oi8rv \ gradle-4.10.2-all.zip   至   C:\ Users \ codeb.gradle \ wrapper \ dists \ gradle-4.10.2-all \ 9fahxiiecdb76a5g3aw9oi8rv

     

欢迎使用Gradle 4.10.2!

     

以下是此版本的重点内容:    -默认情况下增量Java编译    -定期Gradle缓存清理    -Gradle Kotlin DSL 1.0-RC6    -包含的嵌套版本    -plugins {}块中的SNAPSHOT插件版本

     

有关更多详细信息,请参见https://docs.gradle.org/4.10.2/release-notes.html

现在,您可以返回到本机项目并运行

C:\Projects\myproject>react-native run-android
  

info JS服务器已在运行。信息构建和安装应用程序   在设备上(cd android && gradlew.bat app:installDebug)...

     
    

任务:app:installDebug 01:03:18 V / ddms:执行:运行am get-config 01:03:18 V / ddms:在'emulator-5554'上执行'am get-config'     :EOF命中。阅读:-1 01:03:18 V / ddms:执行:返回安装APK     app:debug 01:03:18的'Pixel_2_API_28(AVD)-9'上的'app-debug.apk'     D / app-debug.apk:将app-debug.apk上传到设备“ emulator-5554”上     01:03:18 D /设备:将文件上传到设备'emulator-5554'01:03:18     D / ddms:读取文件的权限     C:\ Projects \ xx \ android \ app \ build \ outputs \ apk \ debug \ app-debug.apk     如:rwx ------ 01:03:18 V / ddms:执行:运行pm install -r -t     “ /data/local/tmp/app-debug.apk” 01:03:19 V / ddms:执行'pm install     -r -t“ emulator-5554”上的“ /data/local/tmp/app-debug.apk”“:EOF命中。读取:-1 01:03:19 V / ddms:执行:返回01:03:19 V / ddms:执行:     运行rm“ /data/local/tmp/app-debug.apk” 01:03:19 V / ddms:执行     emulator-5554上的'rm“ /data/local/tmp/app-debug.apk”':EOF命中。     阅读:-1 01:03:19 V / ddms:执行:返回已安装在1个设备上。

  
     

在9秒钟内成功完成27项可执行任务:已执行1项,最新26项   信息运行   C:\ Users \ codeb \ AppData \ Local \ Android \ SDK / platform-tools / adb -s   emulator-5554反向tcp:8081 tcp:8081信息在以下位置启动应用程序   仿真器-5554   (C:\ Users \ codeb \ AppData \ Local \ Android \ SDK / platform-tools / adb -s   emulator-5554 shell是启动-n   com.myproject / com.myproject.MainActivity)...开始:   意图{cmp = com.myproject / .MainActivity}

enter image description here