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/' }

    }
}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容