2
respostas

tentei rodar o projeto via usb com um aparelho android no ubuntu, mas não deu, segue a mensagem de erro:

nicolas@Nicolas-HP:~/cliapp$ npx react-native run-android info Starting JS server... info Installing the app...

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings 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 '/home/nicolas/cliapp/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 4s

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 '/home/nicolas/cliapp/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 4s

at makeError (/home/nicolas/cliapp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
at /home/nicolas/cliapp/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 (/home/nicolas/cliapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/home/nicolas/cliapp/node_modules/@react-native-community/cli/build/index.js:142:9)

info Run CLI with --verbose flag for more details.

2 respostas

Olá Nícolas, tudo bem?

Esse erro ocorre porque o comando react-native run-android não consegue encontrar a sua instalação do SDK do Android. Ele está procurando por uma variável de ambiente chamada ANDROID_HOME que aponta para a pasta raiz do SDK. Para corrigir esse erro, você precisa definir essa variável de ambiente.

Uma maneira de fazer isso é editar o arquivo ~/.bashrc no seu terminal e adicionar a seguinte linha:

export ANDROID_HOME=$HOME/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
Mude o caminho para o local onde você instalou o seu SDK do android, depois execute
source ~/.bashrc

Outra alternativa é incluir o caminho do sdk no arquivo android/local.properties

sdk.dir = /caminho/para/sdk

Depois de fazer isso, você deve ser capaz de executar o comando react-native run-android sem problemas e seu aplicativo será instalado no dispositivo conectado via USB. Certifique-se de ter configurado as configurações de desenvolvimento no seu dispositivo Android também.

Se você continuar tendo problemas, tente executar o comando ./gradlew app:installDebug diretamente na pasta android do seu projeto. isso também pode ajudar a identificar qualquer problema adicional com sua configuração do Gradle.

npx react-native run-android info Starting JS server... /bin/sh: 1: /home/nicolas/Android/Sdk/platform-tools/adb: 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... Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details Checking the license for package Android SDK Platform-Tools in /home/nicolas/Android/Sdk/licenses Warning: License for package Android SDK Platform-Tools not accepted. Checking the license for package SDK Patch Applier v4 in /home/nicolas/Android/Sdk/licenses Warning: License for package SDK Patch Applier v4 not accepted. Checking the license for package Android Emulator in /home/nicolas/Android/Sdk/licenses Warning: License for package Android Emulator not accepted. Checking the license for package Android SDK Tools in /home/nicolas/Android/Sdk/licenses Warning: License for package Android SDK Tools not accepted. Checking the license for package Android SDK Build-Tools 30.0.3 in /home/nicolas/Android/Sdk/licenses Warning: License for package Android SDK Build-Tools 30.0.3 not accepted. Checking the license for package Android SDK Platform 31 in /home/nicolas/Android/Sdk/licenses Warning: License for package Android SDK Platform 31 not accepted.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings 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'.

    Failed to install the following Android SDK packages as some licences have not been accepted. patcher;v4 SDK Patch Applier v4 platform-tools Android SDK Platform-Tools platforms;android-31 Android SDK Platform 31 build-tools;30.0.3 Android SDK Build-Tools 30.0.3 emulator Android Emulator tools Android SDK Tools To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager. Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

    Using Android SDK: /home/nicolas/Android/Sdk

  • 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 22s

error Failed to install the app. Please accept all necessary Android SDK licenses using Android SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses". 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'.

    Failed to install the following Android SDK packages as some licences have not been accepted. patcher;v4 SDK Patch Applier v4 platform-tools Android SDK Platform-Tools platforms;android-31 Android SDK Platform 31 build-tools;30.0.3 Android SDK Build-Tools 30.0.3 emulator Android Emulator tools Android SDK Tools To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager. Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

    Using Android SDK: /home/nicolas/Android/Sdk

  • 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 22s

at makeError (/home/nicolas/react-native/cliapp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
at /home/nicolas/react-native/cliapp/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 (/home/nicolas/react-native/cliapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/home/nicolas/react-native/cliapp/node_modules/@react-native-community/cli/build/index.js:142:9)

info Run CLI with --verbose flag for more details.