android - 任务 ':app:compileDebugJavaWithJavac' : 执行失败

标签 android react-native react-native-android react-native-ios

当我尝试 $ react-native run-android在android模拟器上,我收到此错误:

:app:compileDebugJavaWithJavac
/home/user/app/android/app/src/main/java/com/package/MainApplication.java:8: error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage
import com.airlabsinc.RNAWSCognitoPackage;
^
1 error
Incremental compilation of 1 classes completed in 0.448 secs.
: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.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.964 secs
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

然后我的 /home/user/app/android/app/src/main/java/com/package/MainApplication.java 中有 2 个同名导入
这可能会导致问题吗?
这是RN的问题吗?
package com.package;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.amazonaws.RNAWSCognitoPackage; // 1
import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage;
import com.airlabsinc.RNAWSCognitoPackage; // 2
import com.horcrux.svg.SvgPackage;
import com.toast.ToastPackage;
import com.vdi.VDIPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

我的环境:
**Environment**:
  * OS: Linux 4.13
  * Node: 8.9.4
  * Yarn: Not Found
  * npm: 5.6.0
  * Watchman: Not Found
  * Xcode: N/A
  * Android Studio: Not Found

**Packages**: (wanted => installed)
  * react: 16.3.0-alpha.2 => 16.3.0-alpha.2
  * react-native: 0.54.2 => 0.54.2

最佳答案

你不能从 JAVA 的不同包中导入同一个类,我建议你删除第一个导入:

- import com.amazonaws.RNAWSCognitoPackage; // 1 (remove this line)

关于android - 任务 ':app:compileDebugJavaWithJavac' : 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50815811/

相关文章:

android - react native android Task:app:transformClassesWithMultidexlistForRelease失败

android - FFmpeg 支持 libstagefright 硬件解码

android - 如何以编程方式确定 Android 应用程序是否在三星 Galaxy 上进入休眠状态?

react-native - React Native Webview 获取 html

javascript - 从 Kotlin 调用 JavaScript

javascript - 无法正确 trim 和粗体匹配两个字符串中的单词

android - 通过 WorkManager API 在每个星期五安排一个特定任务

java - Android 应用程序意外停止

react-native - 如何管理 React Native 的生命周期

react-native - 使用 react-native router-flux 时,BackHandler 在 react-native 侧菜单中不起作用