[英]Execution failed for task ':app:compileDebugJavaWithJavac
[英]Execution failed for task ':app:compileDebugJavaWithJavac':
當我在 android 模擬器上嘗試$ react-native run-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)
build
文件android>app
的構建文件react-native run-android
有幾種可能,試試哪個合適,
無論您使用什么,您可能都錯過了 RNAWSCognitoPackage 包及其相關服務的一些初始設置。 因此,請檢查安裝設置一次。
如果一切正常,那么另一種情況,android 存儲緩存以更快地構建。 每次安裝新軟件包時,都應該清理代碼並再次運行。
刪除 node_modules 和 Package-lock.json 並運行以下命令
cd android ./gradlew clean ./gradlew cleanBuildCache npm install
一些罕見的情況,你需要試試這個,
npx react-native-clean-project clean-project-auto
不確定這是否是正確的解決方案。 可以試一次嗎!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.