關於react-native引入第三方庫,運行react-native link xxxxx後項目沒法運行

最新版本的react-native中,官方表示將要移除html

AsyncStorage,推薦使用@react-native-community/async-storage,好吧官方常常這麼幹
 
按照官方提示
yarn add @react-native-community/async-storage
react-native link @react-native-community/async-storage
好吧,果真不負衆望的報錯了
錯誤信息以下
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 32 path $[0].name

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

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
76 actionable tasks: 1 executed, 75 up-to-date
error 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
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.

有關環境信息node

info
  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
      Memory: 4.55 GB / 15.95 GB
    Binaries:
      Node: 10.15.3 - D:\node\node.EXE
      Yarn: 1.16.0 - D:\yarn\bin\yarn.CMD
      npm: 6.4.1 - D:\node\npm.CMD

解決方案react

1.清除yarn緩存 yarn cache clean
2.清除npm緩存 npm cache clean -f
3.在項目文件夾中有一個package.json 文件,裏面記錄了該項目全部安裝的依賴環境,若項目文件出現依賴環境報錯的狀況,則能夠刪除依賴node_module文件夾,在從新yarn install 一次 , 從新安裝依賴。
4.對於項目出現出現.../.../debug/.../../文件夾報錯,多是緩存致使的問題,進入android文件夾下,輸入命令 ./gradlew clean 命令清除緩存,也可以使用android studio 中的菜單按鈕的build下的clean project清除環境,在使用rebuild project 從新跑一次項目。
相關文章
相關標籤/搜索