這篇文章主要解決react-native中遇到的bug。
環境:window10java
編譯並運行 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
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
cd project/android //進入當前項目的android文件夾下 gradlew clean cd .. //進入當前項目目錄 react-native run-android //編譯並運行 React Native 應用
../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
npm install
npm start -- --reset-cache
場景描述:在react-native 開發的時候,點擊AVDManager按鈕,出現的報錯信息。
解決方法(參考)git
進入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,安裝成功。
yarn add react-native-gesture-handler react-native link react-native-gesture-handler
new File(rootProject.projectDir, '..\node_modules\react-native-gesture-handler\android') //替換成下面的這個,即在加一個‘\’ new File(rootProject.projectDir, '..\\node_modules\\react-native-gesture-handler\\android')
./index
from react-native\scripts/.
運行下面的命令清除緩存npm
react-native start -- --cache-reset
而後在嘗試react-native
react-native run-android
//直接根據端口找進程,能夠獲得一個PID netstat -ano | findStr "8080" //Find the process name by pid tasklist /fi "pid eq 2216" //殺死進程 taskkill /PID 19856
在寫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
在運行項目應該就能夠了!
解決的方法除了只有先老老實實從手機上卸載原有版本再進行安裝,而adb install -r參數也沒法解決這個問題
問題描述:
執行 react-native run-android後,報錯:
解決方法:
把手機上以前安裝的應用程序刪除,執行
$ adb forward --remove-all $ adb forward tcp:8082 tcp:8082 react-native run-android
搖動手機反應很差,咱們能夠執行下面的命令,跳出選擇項
$ adb sell input keyevent 82
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時間一致,儘可能同時讓二者同時進入下一分鐘。
BUG描述:在scrollView組件中有TextInput組件,當手指聚焦到輸入框中時,手指上滑或者下滑,輸入框中的placeholder內容消失,且頁面不滑動。
解決辦法:
給TextInput 添加屬性multiline={Platform.OS !== 'ios'}
官網解釋是:
若是爲true,文本框中能夠輸入多行文字。默認值爲false。注意安卓上若是設置multiline = {true},文本默認會垂直居中,可設置textAlignVertical: 'top'樣式來使其居頂顯示。
BUG描述:用蘋果電腦開發的項目,打包在win10系統下打開執行下面命令就這樣了
`npm install
react-native run-android`
解決辦法:
https://blog.csdn.net/fxp850899969/article/details/78229758
端口被佔用解決方案:`netstat -ano|findstr "8081" # 找到佔用8080端口的進程,得到它的PIDkill 12345 # 經過PID殺死該進程`