React Native Error:Could not find method google() for arguments [] on repository container

常见错误css

1.RN项目必定要注意版本问题,不管是react native仍是其余组件的版本都必定要注意,否则会报错。尽可能不要使用过高的版本,会有不少的问题。基本上全部的错误若是你实在解决不了均可以经过下降版本解决。html

新版本的react-native初始化的项目会有这个错误(当时是0.59以上的版本报了这个错误),能够下降版本或者以下解决办法java

遇到如下问题的请注意:
Unable to resolve module `./index` from `E:\reactNative\AProject\node_modules\react-native\scripts/.`: The module `./index` could not be found from `E:\reactNative\AProject\node_modules\react-native\scripts/.`. Indeed, none of these files exist: 
这个问题是因为react-native找不到index文件所致使
解决方法:
找到目录文件:node_modules\react-native\scripts\launchPackager.bat
将:
node "%~dp0..\cli.js" start 
修改成:
node "%~dp0..\cli.js" start --projectRoot ../../../ 
重启服务便可node

 

 2.有时候react-native的第三方组件会有Cannot read property xxx' of undefined的错误,多是由于react的版本低致使的,由于高版本的react中再也不有proptypes属性,须要导入prop-types组件。react

如下是我测试demo时使用的版本及用其余版本遇到的问题:android

"dependencies": {
"react": "16.3.1", //该版本不带proptypes属性,须要引入prop-types组件进行属性类型检验
"react-native": "0.55.4",  //最低须要react16.3.1版本,react-native版本和gradle版本须要匹配,不然会报错。而有些组件也会要求和gradle版本匹配。因此,安装时尽可能不要改变gradle版本,能够经过改变组件的版原本适配
"react-native-scrollable-tab-view": "^0.10.0",  //0.7.0版本使用的是react的低版本(带proptypes属性的版本)会报错,后来升级到0.10.0就没问题了
"react-native-tab-navigator": "^0.3.4",  //0.3.3版本使用的是react的低版本(带proptypes属性的版本)
"react-native-swiper": "^1.5.14",  //
"react-native-vector-icons": "^5.0.0",  //以前用4.2.0版本会报Execution failed for task ':react-native-vector-icons:compileReleaseJavaWith 这个错误,后来升级到5.0.0版本就正常了
"react-navigation": "^1.5.11"  //该版本和其高版本对gradle版本的要求彷佛不一样,须要注意一下。
}

  

这是我在网上下载的开源RN项目的依赖版本,供参考。这里使用的都是基于react低版本的(包括proptypes属性的版本)npm

"dependencies": {
    "react": "^16.0.0-alpha.12",//这里的react是低版本(包括proptypes属性的版本),因此其余组件都必须是使用低版本react的版本,不然会报错
    "react-native": "^0.45.1",
    "react-native-deprecated-custom-components": "^0.1.0",
    "react-native-scrollable-tab-view": "^0.7.4",
    "react-native-swiper": "^1.5.3",
    "react-native-tab-navigator": "^0.3.3",                                                                                                                                                                                                                                                                                                          
    "react-native-vector-icons": "^4.2.0"
  },

  

安装问题:json

react-native-vector-icons使用

 
第一步:安装react-native-vector-icons

这里经过yarn安装。yarn add react-native-vector-iconsreact-native

第二步

react-native linkbabel

安装完成

 使用方式见官网:http://npm.taobao.org/package/react-native-vector-icons
 
 
 
3.Error:Could not find method google() for arguments [] on repository container
 该错误和gradle版本有关

修改gradle-wrapper.properties中的值

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

修改成

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

4.error: bundling failed: TypeError: Cannot read property 'bindings' of null

 

When upgrading to 0.56, make sure to bump your babel-preset-react-native package.json dependency to ^5.0.1 or newer.

 

  

 

5.react-native-video ^3.0.0须要使用版本27 SDK和版本27.0.3 BuildTools,因此0.55.0版本的react-native不合适。能够经过升级react-native的版本修改改配置文件中sdk和gradle的版本或者直接修改sdk和gradle的版本(容易引起其余配置错误)。

 

6.error: bundling failed: TypeError: Cannot read property 'bindings' of null (升级到react-native 0.56版本时报的错误)

解决办法:

When upgrading to 0.56, make sure to bump your babel-preset-react-native package.json dependency to ^5.0.1 or newer.

 7.Unable to resolve module 'AccessibilityInfo', when trying to create release bundle(在react-native 0.56.0版本中报的错)

 

It seems like a bug in 0.56 related to dependencies. The "solution" is to find the correct combination of dependencies' versions. We found a workaround by installing those versions EXACTLY:

react-native >> 0.55.4
babel-core >> latest 
babel-loader >> latest
babel-preset-react-native >> 4.0.0
So you have to run those commands in order:

react-native init AwesomeProject
cd AwesomeProject
react-native run-android
npm uninstall react-native
npm install --save react-native@0.55.4
react-native run-android
npm install --save babel-core@latest babel-loader@latest
npm uninstall --save babel-preset-react-native
npm install --save babel-preset-react-native@4.0.0
react-native run-android

 

-------------------------------------------------------------------------------------------------------------------------------------

更新版本

 

若是你要知道如今React Native的最新版本

npm info react-native
 
 

假设如今拿到一个已经在好久之前写好的项目,或者本身的项目须要更新,或者RN更新了,这个时候咱们须要对手上的项目进行更新,以使用更新的API。

这里有两个方法:

  • 修改项目的package.json文件


     
     

    将那个“react-native”后面的版本改成当前最新版本 0.55.4,而后

    npm install

    完成之后,再次查看项目版本就会发现版本已经更新到指定版本了。

  • 或者直接npm

    npm install --save react-native@0.55.4 

版本更新好了以后,剩下的就是更新项目文件了

react-native upgrade 

这个过程比较耗时,会进行一些文件的更改、替换操做。等待完成后,升级就完成了。

有的时候,发现最新版本的RN不稳定,须要回退。

上面两个方法随便选一个,改下版本号,一样的操做, 不赘述。

建立react-native项目

建立通常react-native项目:
react-native init 项目名称
建立指定版本的react-native项目
react-native init 项目名称 --version 0.55.4
注:--version 前面必须两个“-”

 

查看react-native版本
进入项目目录:

react-native -V
注:-V,V必须大写,能够经过react-native -h查看

 cd android 

gradlew clean  清除

相关文章
相关标签/搜索