[英]react-native run-android Fails MacOS
完整的控制台 Output 如下
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 696ms
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 696ms
at makeError (/Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:174:9)
at /Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli/build/index.js:186:9)
bash_profile
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'
請求的附件
已安裝 Android 模擬器Nexus 6P(Android R 和 Pie)
New To React Native 它在 iOS 上完美運行,但無法在 Android 模擬器中啟動
嘗試過的方法
可能是因為上面提到的JDK版本。 您可以通過運行 react native doctor 來驗證
npx @react-native-community/cli doctor
安裝 JDK 1.8 並設置 $JAVA_HOME 環境變量並嘗試再次運行該應用程序。
該錯誤是由於JDK版本較低或未安裝JDK。
只需按照以下步驟即可解決您的問題: 將 node_modules 依賴項噴射/轉換為 AndroidX 假設您有一個 react-native 項目。 您的庫依賴項之一轉換為 AndroidX。,您需要使用新版本。
因此,現在您需要將您的應用程序轉換為 AndroidX,但是您的許多 react-native 庫都附帶原生 Java 代碼並且尚未更新。 這是怎么做的?
First, use Android Studio's refactoring tool to convert your app re: the Android developer docs npm install --save-dev jetifier npx jetify npx react-native run-android (your app should correctly compile and work) Call npx jetify run in the postinstall target of你的 package.json (任何時候你的依賴更新你都必須再次jetify
您也可以點擊此鏈接: https://www.npmjs.com/package/jetifier
隨意任何困惑。
這個鏈接是完整的解決方案,但如果你有win32,這里有一個小問題,但如果你有win64,你對go很好。
**https://www.npmjs.com/package/jetifier#do_you_need_this**
希望這個答案對您有任何問題都可以隨意使用。
請按照以下說明進行更改以解決此錯誤。
安裝Java SDK版本:14以上。
JDK下載鏈接: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html
在
gradle-wrapper.properties
請使用 6.3 或更高版本。
例如: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.