react-native使用第三方库

react-native的第三方库或组件一般有两种,一种是样式相关,不涉及到系统的,如页面导航、轮播图等,这种只需要使用npm install命令安装好即可使用;

另一种是使用到了系统中的一些功能,如录音、拍照等,这种除了要用npm install安装之外,还要使用react-native link命令进行连接,即自动地修改Java代码中相关部分。如果link失败,也可手动修改。

有时添加完第三方库进行编译时会报错如下:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> java.io.IOException: Could not delete path 'D:\AndroidStudioWorkspace\XuehaoMandarin\android\app\build\generated\source\r\debug\android\support'.

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

BUILD FAILED

Total time: 29.198 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

这个报错原因是上一次编译的缓存没有清除,只需进入到android目录下,执行gradlew.bat clean即可清除掉缓存,然后react-native run-android重新编译安卓项目即可。

你可能感兴趣的:(react-native使用第三方库)