React-Native 报错集合及解决方案

1.The SDK directory 'C:\Users\plankton\AppData\Local\Android\android-sdk' does not exist.

解决:因为我配置ANDROID_HOME的时候是复制的官网的地址,所以环境变量错误,找到SDK目录,然后重新设置ANDROID_HOME环境变量即可。

2.'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件

Windows简单粗暴解决方案:添加C:\Users\YOURUSERNAME\AppData\Local\Android\Sdk\platform-toolsPath环境变量,其他请参考Stack Overflow

3.Unable to resolve module AccessibilityInfo from XXX和Modul

这是RN0.56版本的bug,详见issues,解决: 退回版本到0.55yarn remove react-native and yarn add react-native@0.55

4. error: bundling failed: Error: Plugin 0 specified in "C:\Users\Administrator\ Desktop\TestProject\yellowDuck\node_modules\babel-preset-react-native\index .js" provided an invalid property of "default" (While processing preset: "C:\Us...

参考了:CSDN博客,重新安装yarn add babel-preset-react-native@2.1.0

5. Warning: isMounted(…) is deprecated in plain Javascript Classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.

貌似是个Bug,坐等修复,issue地址
但是不影响运行,也可以忽略,或者不显示警告,index.js文件中添加下面代码:

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);
6.Package com.yellowduck signatures do not match the previously installed version; ignoring!

这个原因是因为手机未彻底删除应用程序,(我是直接拖到桌面顶部删除),而后来这个打包程序是其他平台打包的(网上说的平台,暂不知是平台还是因为换了台电脑,或者是我安装的Android SDK版本不一样造成),所以签名不一致。解决方法:确保adb devices能看到你的设备,且最好关闭Android虚拟机,使用adb命令: adb uninstall com.你的项目名字(项目名字前面加上com.)

7.React Native version mismatch.
JavaScript version: 0.51.0
Native version: 0.49.5

根据错误提示是因为项目中RN版本过低导致,解决方法:更新项目中的RN版本至最新版本。执行如下命令:
npm install --save react-native@0.51.0
版本不同,构建的项目模板也会发生变化,所以在更新了React Native版本之后,也要及时更新项目模板。
通过如下命令:
react-native upgrade
参考:简书

8.Error:Failed to resolve: android.arch.core:common:1.1.0

原因:升级了react-native版本,没有关闭上一个app的node服务器,在Android目录中的build.gradle中,找到如下代码段

allprojects {
    repositories {
        mavenLocal()
        // 加入下面这行,并且让他在jcenter函数前面运行
        maven { url "https://maven.google.com" }
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

参考:stackoverflow

9.Could not find support-vector-drawable.aar (com.android.support:support-vector-drawable:27.1.1).

找到Android目录下build.gradle文件,找到allprojects做如下修改:

allprojects {
    repositories {
        // 加入下面这行,并且让他在jcenter函数前面运行
        maven { url "https://maven.google.com" }
        jcenter()
    }
}
10.Execution failed for task ':app:processDebugResources'.

参考: stackoverflow

cd android && gradlew clean

cd .. && react-native run-android

11.Could not find method compile() for arguments [com.facebook.fresco:animated-gif:0.13.0] on object of type org. gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

应该添加在android/app/build.gradledependencies
加入compile 'com.facebook.fresco:animated-gif:1.10.0'

12.使用react-native-fs这个库的时候,报错Cannot read property 'RNFSFileTypeRegular' of undefined

解决:执行以下步骤
1.npm install react-native-fs or yarn add react-native-fs
2.react-native link react-native-fs
详见:issues

13.Flat List - ScrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed
14.Could not resolve all artifacts for configuration ':app:releaseStagingRuntimeClasspath'.Could not resolve project:react-native-splash-screen.

原因:第三方包不知道你打包的类型是release还是debug版本,打开android/app/build.gradle文件,添加如下:

    buildTypes {
        
        release {// 对应Production环境
            ...
            matchingFallbacks = ['release', 'debug']
        }
    }
15.Execution failed for task ':app:packageRelease'com.android.ide.common.signing.KeytoolException:Failed to read key meihuo from store "C:\Users\Administrator\Desktop\meihuo.jks":Keystore was tampered with, or password was incorrect

jks签名问题,集成 bugly 时按照他们给的文档我们应该是把签名放在 build.gradle 里,但是我们直接放进去可以能会有错误,

16.Execution failed for task':app:transformClassesWithDesugarForDebug'. >com.android.build.api.transform.TransformException: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'C:\Program Files\Java\jdk1.8.0_191\bin\java.exe''

项目升级了classpath 'com.android.tools.build:gradle:3.1.4'gradle版本为3.3后有修改为3.1.4,能够打包,但是打包debug的时候,和安装到虚拟机调试的时候,报这个错
解决
gradle.properties中添加android.enableD8.desugaring = true

16.隐藏开发模式所有黄色警告
import { YellowBox } from "react-native";
console.disableYellowBox = true;
console.warn('YellowBox is disabled.');
17.https://jcenter.bintray.com/ 服务器崩溃502解决办法
  • android/build.gradle文件替换jcenter()
repositories {
    google()
    maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
//    jcenter()
  
}
allprojects {
    repositories {
        mavenLocal()
        google()
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        // jcenter()
        // jcenter() { url 'http://jcenter.bintray.com/' }

    }
}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,640评论 6 507
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,254评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,011评论 0 355
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,755评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,774评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,610评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,352评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,257评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,717评论 1 315
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,894评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,021评论 1 350
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,735评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,354评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,936评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,054评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,224评论 3 371
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,974评论 2 355

推荐阅读更多精彩内容