#react-native BUG#

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

Error: Command failed: gradlew.bat installDebug

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

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'.

解决方案:react

  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

这个是缓存问题android

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`.

解决方案ios

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

emulator: ERROR: x86 emulation currently requires hardware acceleration!

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

  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’。
    这个问题的解决方法是(参考):github

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

Unable to resolve module ./index from react-native\scripts/.

运行下面的命令清除缓存npm

react-native start -- --cache-reset

而后在尝试react-native

react-native run-android

Error: listen EADDRINUSE :::8081

//直接根据端口找进程,能够获得一个PID
netstat -ano | findStr "8080"
//Find the process name by pid
tasklist /fi "pid eq 2216"
//杀死进程
taskkill /PID 19856

SyntaxError: /Checkbox/checkbox.js: Unexpected token (14:32)

clipboard.png
在写react项目的时候剩余运算符解析报错。
解决方案:
解构对象须要用到 stage-3 的 preset。缓存

//安装stage-3
npm install --save-dev @babel/preset-stage-3
//配置
{
  "presets": ["stage-3"]
}

到这里从新运行项目可能会遇到这样的bug信息:
Error: Couldn't find preset "stage-3" relative to directory
这时咱们能够尝试安装

npm install --save-dev babel-preset-stage-2

在运行项目应该就能够了!


INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES

解决的方法除了只有先老老实实从手机上卸载原有版本再进行安装,而adb install -r参数也没法解决这个问题

Unable to connect with remote debugger

问题描述:
执行 react-native run-android后,报错:

clipboard.png

clipboard.png

clipboard.png

解决方法:
把手机上以前安装的应用程序删除,执行

$ adb forward --remove-all
$ adb forward tcp:8082 tcp:8082
react-native run-android

页面刷新

摇动手机反应很差,咱们能够执行下面的命令,跳出选择项

clipboard.png

$ adb sell input keyevent 82

Attempted to transition from state RESPONDER_INACTIVE_PRESS_IN to RESPONDER_ACTIVE_LONG_PRESS_IN, which is not supported.

参考: https://github.com/facebook/r...

I 'fixed' this by manually setting the device time in Android. Make sure the new time will equal that of your computer (aim for the next minute change), confirm the time change on the very same second your computer time will change to the next minute.

方法:让PC和phone时间一致,尽可能同时让二者同时进入下一分钟。

TextInput

BUG描述:在scrollView组件中有TextInput组件,当手指聚焦到输入框中时,手指上滑或者下滑,输入框中的placeholder内容消失,且页面不滑动。
解决办法:
给TextInput 添加属性
multiline={Platform.OS !== 'ios'}
官网解释是:

若是为true,文本框中能够输入多行文字。默认值为false。注意安卓上若是设置multiline = {true},文本默认会垂直居中,可设置textAlignVertical: 'top'样式来使其居顶显示。

React Native CLI uses autolinking for native dependencies, but the following modules are linked manu

BUG描述:用苹果电脑开发的项目,打包在win10系统下打开执行下面命令就这样了
`npm install
react-native run-android`
解决办法:
image.png

Exception in thread "main" java.util.zip.ZipException: error in opening zip file

https://blog.csdn.net/fxp850899969/article/details/78229758

error listen EADDRINUSE :::8081. Run CLI with --verbose flag for more details.

命令行工具使用的是 bash

端口被占用解决方案:`netstat -ano|findstr "8081" # 找到占用8080端口的进程,得到它的PIDkill 12345 # 经过PID杀死该进程`

相关文章
相关标签/搜索