简体   繁体   中英

Java cannot find '/platform-tools/adb' (Building app with react-native)

I run npx react-native run-android and I get this

This seems to be the problem, It's looking for platform tools in ~/ and not in ~/Android/Sdk

java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory `

You can ignore this, stack won't let me post this if I don't add more text, but I think it's already a good explanation

> Task :app:compileDebugJavaWithJavac

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libbetter.so, libc++_shared.so, libevent-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libfabricjni.so, libfb.so, libfbjni.so, libflipper.so, libfolly_futures.so, libfolly_json.so, libglog.so, libglog_init.so, libimagepipeline.so, libjsc.so, libjscexecutor.so, libjsi.so, libjsijniprofiler.so, libjsinspector.so, liblogger.so, libmapbufferjni.so, libnative-filters.so, libnative-imagetranscoder.so, libreact_codegen_rncore.so, libreact_debug.so, libreact_nativemodule_core.so, libreact_render_animations.so, libreact_render_attributedstring.so, libreact_render_componentregistry.so, libreact_render_core.so, libreact_render_debug.so, libreact_render_graphics.so, libreact_render_imagemanager.so, libreact_render_leakchecker.so, libreact_render_mapbuffer.so, libreact_render_mounting.so, libreact_render_runtimescheduler.so, libreact_render_scheduler.so, libreact_render_telemetry.so, libreact_render_templateprocessor.so, libreact_render_textlayoutmanager.so, libreact_render_uimanager.so, libreact_utils.so, libreactconfig.so, libreactnativeblob.so, libreactnativejni.so, libreactnativeutilsjni.so, libreactperfloggerjni.so, librrc_image.so, librrc_modal.so, librrc_progressbar.so, librrc_root.so, librrc_scrollview.so, librrc_slider.so, librrc_switch.so, librrc_text.so, librrc_textinput.so, librrc_unimplementedview.so, librrc_view.so, libturbomodulejsijni.so, libyoga.so.

> Task :app:installDebug FAILED
31 actionable tasks: 31 executed
Note: /home/u/Desktop/workdir/Math_App/mathapp/android/app/src/debug/java/com/mathapp/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[adb]: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory

* 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 13m 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
Note: /home/u/Desktop/workdir/Math_App/mathapp/android/app/src/debug/java/com/mathapp/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[adb]: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory

* 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 13m 4s

    at makeError (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
    at /home/u/Desktop/workdir/Math_App/mathapp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/@react-native-community/cli/build/index.js:192:9)

Check where your $ANDROID_HOME variable is pointing to.

echo $ANDROID_HOME

If must be equal to the path of Android/Sdk , usually at ~/Android/Sdk

A solution, if you know where the variable ANDROID_HOME is (maybe ~/.bashrc , ~/.profile ):

Go to the file you've the var ANDROID_HOME and edit it so it looks like this

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

After you changed them, do source.bashrc or source {whatever file they're on} and it should work (it works on the terminal you did it, it, do it in whatever terminal you want it to work, if it's on .bashrc it'll work next time you restart without doing source)

That's how it's done if Android is installed in ~/ (you can check out by doing cd , and then ls , Android should appear, if it didn't, change $HOME for the direction of where you installed it).

If you don't have those variables at all: just open ~/.bashrc and add them to the file. And do the same as it's explained before.

And yeah, that's it. I'd appreciate if someone translated this to the Windows and Mac way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM