ReactNative Mac配置安卓真机调试环境

其实Mac下配置安卓环境可以通过AndroidStudio来完成,这个度娘上有很多的资料,在这记录下我绕过AndroidStudio进行安卓的真机调试的配置过程。

贴上运行时的报错信息:No connected devices!

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':app:installDebug'.
com.android.builder.testing.api.DeviceException: No connected devices!
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED

好了,下面进入正题,开始配置


一、Android SDK Manager

1、先自行下载好Android SDK Manager,没有下载的可以点这里
2、进入tools目录下执行./android sdk,打开Manager界面
ReactNative Mac配置安卓真机调试环境_第1张图片
3、根据自己需要,下载对应的SDK


二、配置环境变量

1、新建/进入配置文件

$ touch  ~/.bash_profile  

2、将adb加入环境变量

【路径根据上一步安装AndroidSDKManager设置】

$ export PATH=${PATH}:/Users/zeng/android-sdk/platform-tools/  

3、将tools加入环境变量

【路径根据上一步安装AndroidSDKManager设置】

$ export PATH=${PATH}:/Users/zeng/android-sdk/tools  

4、保存退出.bash_profile文件,执行source ~/.bash_profile,或退出终端

5、验证adb配置是否成功

$ adb version 

验证成功,输出对应版本以及路径,并且路径与之前配置的adb路径一致
ReactNative Mac配置安卓真机调试环境_第2张图片


三、连接设备

1、将android设备连接到电脑,确保电脑能够读取手机数据

⚠️不确定电脑能够读取手机数据的,下载AndroidfFileTransfer,使用工具来进行确认,下载地址在这里
ReactNative Mac配置安卓真机调试环境_第3张图片

⚠️手机在设置中一定要打开开发者模式,在开发者选项中选择USB配置为:传输文件(MTP)
ReactNative Mac配置安卓真机调试环境_第4张图片

2、 查看usb设备信息,以下只为部分截图

$ system_profiler SPUSBDataType

⚠️保存vendor ID: 0x2717
ReactNative Mac配置安卓真机调试环境_第5张图片

3、创建adb_usb.ini文件,在文件中添加0x2717后保存退出

$ vi ~/.android/adb_usb.ini

4、重启finder :鼠标单击窗口左上角的苹果标志–>强制退出–>Finder–>重新启动


四、重启adb

$ adb kill-server

$ adb start-server

$ adb devices

可以看到连接的设备列表了
ReactNative Mac配置安卓真机调试环境_第6张图片

五、运行

$ react-native run-android

ReactNative Mac配置安卓真机调试环境_第7张图片


最后

说说配置过程中遇到的一些坑吧~

1、 缺少SDK

Total time: 3.638 secs

Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
[Android SDK Platform 25].
Before building your project, you need to accept the license agreements and comp
lete the installation of the missing components using the Android Studio SDK Man
ager.
Alternatively, to learn how to transfer the license agreements from one workstat
ion to another, go to http://d.android.com/r/studio-ui/export-licenses.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

这个报错看起来很多很可怕,但其实核心也就一句话You have not accepted the license agreements of the following SDK components:
[Android SDK Platform 25],把它提示的相关SDK去Android SDK Manager里面下载下来就行了

2、小米系统的坑,博主MI 5s哒

com.android.ddmlib.InstallException: Failed to establish session

碰上这个问题的解决方法:小米手机设置里->开发者选项->启用MIUI优化关闭

你可能感兴趣的:(ReactNative,Mac)