#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殺死該進程`

相關文章
相關標籤/搜索