Java 找不到“/platform-tools/adb”(使用本机构建应用程序)

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

我 运行 npx react-native run-android 我明白了

这似乎是问题所在,它在 ~/ 而不是 ~/Android/Sdk

中寻找平台工具

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

你可以忽略这个,堆栈不会让我post如果我不添加更多文本,但我认为这已经是一个很好的解释

> 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)

检查您的 $ANDROID_HOME 变量指向的位置。

echo $ANDROID_HOME

如果必须等于Android/Sdk的路径,通常在~/Android/Sdk

一个解决方案,如果你知道变量ANDROID_HOME在哪里(可能是~/.bashrc~/.profile):

转到您拥有 var ANDROID_HOME 的文件并编辑它,使其看起来像这样

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

更改它们后,执行 source .bashrcsource {whatever file they're on} 它应该可以工作(它可以在你做的终端上工作,它,在任何你想让它工作的终端上做,如果它在 .bashrc 下一次你重新启动而不做 source 时它会工作)

如果在~/中安装了Android就是这样了(你可以通过cd查看,然后lsAndroid应该出现,如果它没有,将 $HOME 更改为您安装它的方向。

如果您根本没有这些变量:只需打开 ~/.bashrc 并将它们添加到文件中。并按照之前解释的方式进行操作。

是的,就是这样。如果有人将其翻译成 WindowsMac 方式,我将不胜感激。