[開發問題]React-native問題集

weixin_33670713發表於2018-08-23

1.0 Could not expand ZIP '

Could not expand ZIP ' 'D:\Project\React\myapp\node_modules\react-native\android\com\facebook\react\react-native\0.48.4\react-native-0.48.4.aar'.

cd android 
gradlew clean 
cd ..
react-native run-android

2.0下載gradle非常慢

下載gradle到本地某個磁碟,比如我放在D盤gradle資料夾下,
然後替換專案中android/gradle/wrapper/gradle-wrapper.properties 檔案的 distributionUrl=file:///D:/gradle/gradle-<versionCode>-all.zip,重新執行react-native run-android/react-native run-ios,等待執行完畢

3.0 Unable to resolve module 'AccessibilityInfo

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:

  1. Clear watchman watches: watchman watch-del-all.
  2. Delete the node_modules folder: rm -rf node_modules && npm >install.
  3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-* or npm start -- --reset-cache.
  4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*.

解決方案:

  • npm uninstall -g react-native-cli
  • npm uninstall -g react-native
    再裝上新版本:
  • npm install -g react-native@0.55.4
  • npm install -g react-native-cli@1.2.0
    再在專案初始化的時候指定 React Native 版本:
  • react-native init --version="0.55.4" myFirstApp

4.0 啟動報錯項

FAILURE: Build failed with an exception.
Execution failed for task ':app:processDebugResources'.
java.io.IOException: Could not delete path 'D:\Project\React\React-Native\LearnRN\android\app\build\generated\source\r\debug\android\arch\lifecycle\livedata'.

清手機快取之後ok

5.0 插入文字報錯

ReacNative:報錯Cannot add a child that doesn't have a YogaNode to a parent without a measure function!

不能直接新增文字到RN標籤中,需要用Text標籤包裹

6.0 react-navigation 標題在安卓上不居中問題
export const AppStackNavigator = StackNavigator({
    HomePage:{
        screen:HomePage,
        navigationOptions:{
            // header:null//隱藏區域性的導航欄
            title:"Home",
            headerTitleStyle:{
                textAlign:'center',
                flex:1
            }
        }
    })

7.0 Gradle版本造成的問題

在我用以下版本使用ract-native-vector-icons 的時候一直出現Could not find method google() for arguments [] on repository container,或者implement for argument......

Gradle 外掛版本、Gradle發行版本以及 Android SDK Build Tools 版本造成的問題,

//andorid/build.gradle
dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'//這裡要3.0+版本

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
//package.json
  "react-native": "0.55.4",

最直接的方法,升級react-native為最新

8.0 執行最新react-native init ProjectName出現的警告導致的報錯

[3/4] Linking dependencies...
warning "react-native > metro-babel-register > @babel/plugin-proposal-class-properties@7.1.0" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "react-native > metro-babel-register > @babel/plugin-proposal-nullish-coalescing-operator@7.0.0" has unmet peer dependency "@babel/core@^7.0.0-0"........

缺少依賴,本地安裝

npm install @babel/core @babel/runtime   --save 

相關文章