这篇文章主要解决react-native中遇到的bug。
环境:window10

Error: Command failed: gradlew.bat installDebug

编译并运行 React Native 应用之前我们可以使用下面的方法清理gradlew 和之前的构建文件。

Error: Command failed: gradlew.bat installDebug
Failed to capture snapshot of output files for task':app:transformClassesWithDexBuilderForDebug' 
property 'streamOutputFolder' during up-to-date check.
Could not read path
'project\android\app\build\intermediates\transforms\dexBuilder\debug\49\android\arch\lifecycle'.

解决方案:

  1. 在项目下运行这面的命令
    在项目目录下输入下面的命令:react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  2. 依次执行下面的命令
cd project/android   //进入当前项目的android文件夹下
gradlew clean
cd ..   //进入当前项目目录
react-native run-android  //编译并运行 React Native 应用

The module ../lib/props could not be found from `projectnode_modulesreact-native-svgelementsRect.js

这个是缓存问题

bundling failed: Error: Unable to resolve module `../lib/props` from `project\node_modules\react-native-svg\elements\Rect.js`: The module `../lib/props` could not be found from `project\node_modules\react-native-svg\elements\Rect.js`.

解决方案

  1. 删除项目中的node_modules文件夹
  2. 重新下载依赖
    执行下面的命令npm install
  3. 清空缓存
    执行下面的命令npm start -- --reset-cache

emulator: ERROR: x86 emulation currently requires hardware acceleration!

场景描述:在react-native 开发的时候,点击AVDManager按钮,出现的报错信息。
解决方法(参考

  1. 在Android Studio中打开SDK Manager并且下载Intel x86 Emulator Accelerator (HAXM installer)。
  2. 进入SDK目录
    目录结构大致这样: C:users%USERNAME%AppDataLocalAndroidsdkextrasintelHardware_Accelerated_Execution_Manager
    执行安装这个文件: intelhaxm-android.exe。
    执行的过程中可能会报错这样的信息:‘Intel virtualization technology (vt,vt-x) is not enabled’。
    这个问题的解决方法是(参考):

    - Please reboot your system and enter the BIOS setup // win10 开机的时候一直按着esc键。    
    - Look for an option labeled "VT", "Intel VT", or "Virtualization"; verify it is enabled. 
    - If VT/Intel VT/Virtualization is disabled, enable the option.   
    - Save the BIOS settings.    
    - Restart the machine.
    - 执行安装这个文件: intelhaxm-android.exe,安装成功。 
  3. 重启Android Studio再次点击 AVDManager应该就不会报错了.

undefined is not an object (evaluating 'RNGestureHandlerModule.State')

yarn add react-native-gesture-handler
react-native link react-native-gesture-handler

settings file 'projectandroidsettings.gradle': 3: unexpected char: '\' @ line 3, column 133

new File(rootProject.projectDir, '..\node_modules\react-native-gesture-handler\android')
//替换成下面的这个,即在加一个‘\’
new File(rootProject.projectDir, '..\\node_modules\\react-native-gesture-handler\\android')
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐