React-Native: "adb"未被识别为内部或外部命令、可操作的程序或批处理文件。

20

我是 React Native Android 应用开发新手,请求帮忙解决这个问题。

我无法运行我的第一个应用程序,出现错误提示:adb' is not recognized as an internal or external command, operable program or batch file.

我在 android sdk->platform-tools 文件夹下检查了一下,发现有 adb.exe 文件。

构建成功,但在运行时出现错误。以下是我的 cmd 提示符

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
E:\ReactWorkSpace\MyFirstApp>react-native run-android
Scanning 560 folders for symlinks in E:\ReactWorkSpace\MyFirstApp\node_modules (72ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library
:app:prepareComAndroidSupportRecyclerviewV72340Library
:app:prepareComAndroidSupportSupportV42340Library
:app:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library
:app:prepareComFacebookFrescoDrawee101Library
:app:prepareComFacebookFrescoFbcore101Library
:app:prepareComFacebookFrescoFresco101Library
:app:prepareComFacebookFrescoImagepipeline101Library
:app:prepareComFacebookFrescoImagepipelineBase101Library
:app:prepareComFacebookFrescoImagepipelineOkhttp3101Library
:app:prepareComFacebookReactReactNative0434Library
:app:prepareComFacebookSoloaderSoloader010Library
:app:prepareOrgWebkitAndroidJscR174650Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:transformClassesWithDexForDebug
Running dex in-process requires build tools 23.0.2.
For faster builds update this project to use the latest build tools.
:app:mergeDebugJniLibFolders
:app:transformNative_libsWithMergeJniLibsForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug
:app:validateSigningDebug
:app:packageDebug
:app:assembleDebug
:app:installDebug
Installing APK 'app-debug.apk' on 'A16 - 4.2.2' for app:debug
Installed on 1 device.

BUILD SUCCESSFUL

Total time: 7 mins 4.412 secs
'adb' is not recognized as an internal or external command,
operable program or batch file.
Starting the app (D:\Android\sdk/platform-tools/adb shell am start -n com.myfirstapp/.MainActivity...
Starting: Intent { cmp=com.myfirstapp/.MainActivity }

E:\ReactWorkSpace\MyFirstApp>

我没有使用模拟器,而是使用自己的手机设备。应用在我的设备上启动,但我看到的只有一个白色的空白屏幕。我按照官方网站上提供的所有说明正确操作了。

谢谢。

6个回答

41

我找到了解决方法。

你需要将ADB的路径添加到系统变量中。

复制ADB的位置,然后进入控制面板->系统->高级系统设置->环境变量->在系统变量下找到PATH变量,先选中它,再点击编辑,然后点击新建并粘贴ADB的路径,最后点击确定。问题就解决了。

现在重新启动命令提示符,运行react-native run-android。 它会工作 :)

希望这能帮助到有需要的人。感谢查看我的问题。


7
我该在哪里找到adb路径? - Operator
6
@Operator,它应该在你安装它的文件夹里。如果你使用了Android Studio,理想的路径是C:\Users[user]\AppData\Local\Android\android-sdk\platform-tools\adb.exe。因此该路径就是你保存adb.exe文件的地方。 - basavaraj_S
1
在我的情况下,在将adb路径添加到系统变量后,我不得不重新启动我的桌面。 - Mohammad Abdul Alim

5

这取决于你使用的集成开发环境(IDE),如果你正在使用 Webstorm,你需要转到设置 -> 外观和行为 -> 路径变量。

现在你将得到可能为空的新窗口。在右上角,你会看到一个“+”符号,你需要选择它并设置你的变量。

我的变量如下:

名称: ANDROID_HOME 值: D:\Android_SDK\platform-tools。


1
我曾多次遇到这个问题,给出的答案确实可以解决它,但最近我又遇到了这个错误,但是构建成功了,我不能用这种方法修复它。我发现这是模拟器的互联网连接错误。
如果您也遇到这个问题,请重新启动模拟器,并确保您可以打开Google Chrome上网。

1
您看到空白屏幕是因为您的服务器未运行或已停止。
如果您正在使用USB进行调试,请运行adb reverse
尝试将笔记本电脑和手机连接到同一WiFi,并在开发设置中输入您的IP地址:8081。

0

我遇到了这个问题,即使你按照步骤正确地操作,除非你采用这个解决方案,否则它将无法运行。

对于react-native-cli,如果你正在运行更新的版本,你必须安装"Java 11",如果你正在运行旧版的react native,则尝试安装"Java 8"。

(请注意,您需要重新启动系统)


0
如果您的Metro已经启动但仍然出现此错误,请运行以下命令: adb reverse tcp:8081 tcp:8081。应用程序将在设备上成功运行。adb reverse tcp:8081 tcp:8081 如果出现此类错误:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接