1
resposta

Erro ao usar comando npx react-native run-android

Ao iniciar o curso fiz todo procedimento e conseguir rodar o emulador IOS, agora estou com problemas ao rodar o projeto no emulador android:

O erro que tenho no terminal é esse :

FCxLabs@Mac-mini-de-Kelvin android % npx react-native run-android
warn Multiple Podfiles were found: ios/Podfile,vendor/bundle/ruby/2.6.0/gems/cocoapods-core-1.12.1/lib/cocoapods-core/Podfile. Choosing ios/Podfile automatically. If you would like to select a different one, you can configure it via "project.ios.sourceDir". You can learn more about it here: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
info JS server already running.
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
5 actionable tasks: 5 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/android/local.properties'.

* 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 1s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/android/local.properties'.

* 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 1s

    at makeError (/Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
    at /Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (/Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:82:7)
    at async Command.handleAction (/Users/FCxLabs/Documents/Curso-react-native/AwesomeProject/node_modules/@react-native-community/cli/build/index.js:108:9)
info Run CLI with --verbose flag for more details.
FCxLabs@Mac-mini-de-Kelvin android % 
1 resposta

Olá, Alysson!

Pelo erro apresentado, parece que você está com problemas para rodar o projeto no emulador Android devido a algumas configurações faltantes. O erro menciona que não foi encontrada a localização do SDK.

Uma possível solução é definir a localização do SDK do Android definindo a variável de ambiente ANDROID_HOME. Para fazer isso, siga os passos abaixo:

  1. Abra o Terminal.
  2. Digite o comando echo $ANDROID_HOME para verificar se a variável já está definida. Se não houver nenhuma saída, isso significa que a variável não está definida.
  3. Em seguida, digite o comando export ANDROID_HOME=/caminho/para/o/sdk substituindo "/caminho/para/o/sdk" pelo caminho correto para a pasta do SDK do Android em seu computador.
  4. Tente rodar novamente o comando npx react-native run-android e verifique se o erro persiste.

Além disso, certifique-se de ter seguido todos os passos corretamente para configurar o ambiente de desenvolvimento do React Native para Android. Você pode encontrar mais informações sobre isso na documentação oficial do React Native: https://reactnative.dev/docs/environment-setup.

Espero que isso ajude a resolver o problema! Se você tiver mais alguma dúvida, é só perguntar. Bons estudos!