3
respostas

Problema para rodar npx react-native run-android

Boa tarde,

Quando rodo o comando "npx react-native run-android" ele chega a abrir o emulador mas não instala o app (projeto), a mensagem é:

PS C:\Users\hitom> npx react-native run-android
error Unrecognized command "run-android".
info Run "react-native --help" to see a list of all available commands.
PS C:\Users\hitom> cd teste
PS C:\Users\hitom\teste> npx react-native run-android
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 Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
11 actionable tasks: 2 executed, 9 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_261 contains a valid JDK installation.

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

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

E quando escrevo "npx react-native info" aparece:

PS C:\Users\hitom\teste> npx react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.19041
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 1.03 GB / 7.90 GB
  Binaries:
    Node: 12.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.1
      System Images: android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6626763
  Languages:
    Java: 11.0.8 - C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin\javac.EXE
    Python: 2.7.2 - C:\Python27\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
  npmGlobalPackages:
    *react-native*: Not Found

Gostaria de ajuda, agradeço desde já.

3 respostas

Olá daniprigoli, tudo bem?

Pelo logde erro ele está com dificuldade em fazer a compilação android, acredito que os seguintes passos auxiliariam:

  • Fazer download da JDK8no seguinte link
  • Adicionar no path a variável JAVA_HOME, com por exemplo:
    JAVA_HOME C:\\Program Files\Java\jdk.1.8

Caso você já tenha o Java8 instalado você pode apenas colocar no path como citei anteriormente o endereço para jdk

Trocando corretamente para o endereço de instalação em seu computador :)

Dessa forma ao tentar executar o comando acredito que ele encontrará corretamente :)

Pode testar ?

Abraços e Bons Estudos!

Teste, tentei usar o "npx react-native run-android" e apareceu:

PS C:\Users\hitom\teste> npx react-native run-android
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 Starting JS server...
* daemon not running; starting now at tcp:5037
* daemon started successfully
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
11 actionable tasks: 2 executed, 9 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_261 contains a valid JDK installation.

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

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

e quando escrevo "npx react-native info"

PS C:\Users\hitom\teste> npx react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.19041
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 755.84 MB / 7.90 GB
  Binaries:
    Node: 12.18.2 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.1
      System Images: android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6626763
  Languages:
    Java: 11.0.8 - C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin\javac.EXE
    Python: 2.7.2 - C:\Python27\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
  npmGlobalPackages:
    *react-native*: Not Found

Vi também outras pessoas adicionando um novo arquivo "local.properties" com "sdk.dir = C:\Users(caminho)\Android\Sdk" tentei mas deu:

$ npx react-native run-android
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...
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.teste/.MainActivity }
Error type 3
Error: Activity class {com.teste/com.teste.MainActivity} does not exist.

Estou muito perdida, agradeço desde já.

Dani, você pode tirar um print das variáveis de ambiente?

E fazer upload em qualquer site e me mandar o link para eu dar uma olhada?

Pelo log ele está tentando utilizar a jre, veja:

Please check that C:\Program Files (x86)\Java\jre1.8.0_261

Ao invés de utilizar a jdk

Veja se nessa pasta : C:\Program Files(x86)\Java tem uma pasta chamada jdk1.8.0_261

Caso tenha, adicione no PATH digitando no terminal:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_261

Ou acessando da mesma forma que foi necessário para oANDROID_HOME

Caso não tenha, ai será necessário colocar o caminho correto para a jdkque você fez download

Você pode estar colocando também no Patho endereço para o binário do java, no caso:

C:\Program Files\Java\jdk1.8.9_261\bin

Mas acredito que apenas setar o JAVA_HOME funcione corretamente, mas aguardo um print das variáveis

Esse vídeo também mostra muito bem como fazer a configuração, você pode dar uma olhada para ver se em algum momento não esqueceu de nada:

Observe que quando ele vai inserir o ANDROID_HOME(10min14s) a configuração do JAVA_HOME está presente

Abraços :)

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software