react-native常见错误整理

摘要:
所以打包apk前不用执行react-nativebundle命令来打出jsbundle,assembleRelease已经包含了这个功能,这回导致资源文件重复而报错。该删的都删掉吧!
更多内容参见个人技术博客,无广告欢迎关注

1、CFBundleIdentifier", Does Not Exist

sudo rm -rf node_modules && rm -rf ~/.rncache && yarn

sudo npm install -g react-native-git-upgrade

2、Build input file cannot be found: 'xxx/third-party/double-conversion-1.1.5/'…

新建的React Native 项目,凡是版本号大于0.45的,iOS版本在build的时候会卡在build double conversion 这里。

3、third-party/glog-0.3.4/src/base/mutex.h:105:10: 'config.h' file not found

cd node_modules/react-native/third-party/glog-0.3.4

../../scripts/ios-configure-glog.sh

4、React Native version mismatch

react-native常见错误整理第1张

watchman watch-del-all && react-native start --reset-cache

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 -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.

5、权限问题

chown -R wood:staff~/.npm 让该目录下的所有文件都有wood用户权限

groups查看当前用户所属组

groups wood 查看指定用户所属组

id -awood 可以查到指定用户所属组更详细的信息

whoami 查看当前用户的用户名

6、Execution failed for task ':app:installDebug'.

at com.android.ddmlib.Device.installPackage(Device.java:869)

> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_FAILED_INSUFFICIENT_STORAGE

at com.android.builder.testing.ConnectedDevice.installPackage

是因为包名和签名的信息与原先手机上的冲突,最简单的方式,通过adb uninstall packageName将原来的App卸载干净,重新执行就可以成功了

7、Attempted to transition from state RESPONDER_INACTIVE_PRESS_IN to RESPONDER_ACTIVE_LONG_PRESS_IN, which is not supported. This is most likely due to Touchable.longPressDelayTimeout not being cancelled.

https://github.com/facebook/react-native/issues/5823

这是开启了Debug JS Remotely模式

8、React-Native判断Debug/Release

//Android Studio项目中if(BuildConfig.DEBUG){
//debug模式
}
else{
//release模式
}

iOS项目判断方法

#ifdef DEBUG// debug模式#else//release 模式#endif

React-Native项目判断方法

if(__DEV__){
// debug模式
}
else{
// release模式
}

Android打包

build_apk.sh
#!/bin/bash
rm android/app/build/outputs/app-release.apk
cdandroid
./gradlew assembleRelease

react-native ->jsbundle,将RN代码和资源文件打包成jsbundle放在app或apk中,这样可以不依赖于开发服务器在真机上运行

react-native bundle 命令

iOS项目:

1. 工程目录下执行

react-native bundle --platform ios --entry-file index.js --reset-cache --bundle-output ios/bundle/main.jsbundle --dev false --assets-dest ios/bundle/

2. 在xcode中添加bundle文件夹

3. 在AppDelegate.m中选择使用main.jsbundle

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”index.ios” withExtension:@”jsbundle”];

Android项目:

react-native bundle --platform android --entry-file index.js --reset-cache --bundle-output android/app/src/main/assets/index.android.bundle --dev false --assets-dest android/app/src/main/res/

9、Android生成已签名的apk时构建时可能出现的错误

Duplicate resources

react-native常见错误整理第2张

请删除drawable-xxx下面的资源文件,因为在打包apk官方文档中有说明,Gradle 的assembleRelease参数会把所有用到的 JavaScript 代码都打包到一起,然后内置到 APK 包中。

所以打包apk前不用执行react-native bundle 命令来打出jsbundle,assembleRelease已经包含了这个功能,这回导致资源文件重复而报错。

react-native常见错误整理第3张

该删的都删掉吧!

10、Cannot set build number with plist path containing $(SRCROOT)

Please remove $(SRCROOT) in your Xcode target build settings

react-native常见错误整理第4张

解决方法一:

https://stackoverflow.com/questions/3730186/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-b

解决方法二:

模仿tvOS/Info.plist,去掉$(SRCROOT)改为相对路径

react-native常见错误整理第5张

11、AndroidRCTWeChat接入注意事项

> Task :react-native-update:verifyReleaseResourcesFAILED

FAILURE: Build failed with an exception.

react-native常见错误整理第6张

-----------

debug/release运行没问题,包括用Android Studio生成已签名的apk也没问题,但是自动化打包(./gradlew assembleRelease)失败

react-native常见错误整理第7张

类似这种错误需要做以下修改:

保证app/build.gradle中的dependences与依赖工程中的一致,建议都改为implementation,可以参考国外人写的工程(这里需要吐槽下腾讯)

settings.gradle把react-native-wechat 改为RCTWeChat

rootProject.name = 'superbuy'
include ':react-native-fetch-blob'
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-i18n'
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')
include ':jcore-react-native'
project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')
include ':jpush-react-native'
project(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')
include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':RCTWeChat'
project(':RCTWeChat').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wechat/android')
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-update'
project(':react-native-update').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-update/android')
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':app'

app/build.gradle

compile是过期的用法要改为implementation,并且相应的依赖工程也需要改为implementation

apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
signingConfigs {
config {
keyAlias 'release'
keyPassword 'xxxxxx'
storeFile file('/Users/wood/Documents/xxx/android/keystores/release.keystore')
storePassword 'xxxxxx'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode hasProperty("VERSION_CODE") ? Integer.parseInt(VERSION_CODE) + 1 : 1
project.setProperty("VERSION_CODE", versionCode)
versionName hasProperty("VERSION_NAME") ? VERSION_NAME : "1.0.0"
manifestPlaceholders = [
JPUSH_APPKEY: "xxxxxxxxxxxxxxxxxxx",
APP_CHANNEL : "default"
]
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.config
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_PRODUCTION
buildConfigField "boolean", "IS_CODEPUSH", "true"
}
debug {
applicationIdSuffix ".debug" // 在模拟器上同时安装debug/release包
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
buildConfigField "boolean", "IS_CODEPUSH", "true"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-update')
implementation project(':react-native-code-push')
implementation project(':react-native-fetch-blob')
implementation project(':react-native-update')
implementation project(':react-native-device-info')
implementation project(':react-native-i18n')
implementation project(':jcore-react-native')
implementation project(':jpush-react-native')
implementation project(':react-native-webview')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-video')
implementation project(':react-native-vector-icons')
implementation project(':react-native-splash-screen')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-image-picker')
// 微信不使用自动链接react-native-wechat
implementation project(':RCTWeChat')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
// From node_modules
// 如果你需要支持GIF动图
implementation 'com.facebook.fresco:animated-gif:1.10.0'
// 如果你需要支持WebP格式,包括WebP动图
implementation 'com.facebook.fresco:animated-webp:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.10.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

依赖工程:

RCTWeChat/build.gradle

apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.0"
def DEFAULT_TARGET_SDK_VERSION = 28
android {
// compileSdkVersion 23
// buildToolsVersion "23.0.1"
compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 16
// targetSdkVersion 22
targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
}
allprojects {
repositories {
jcenter()
maven { url "$projectDir/../../react-native/android" }
}
}
dependencies {
implementation 'com.facebook.react:react-native:+' // compile -> implementation
compile files('libs/libammsdk.jar')
}

react-native-fetch-blob/build.gradle

apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.0"
def DEFAULT_TARGET_SDK_VERSION = 28
android {
// compileSdkVersion 23
// buildToolsVersion "23.0.1"
compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 16
// targetSdkVersion 23
targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation 'com.facebook.react:react-native:+' // compile -> implementation
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
}

react-native-i18n/build.gradle

dependencies {
implementation "com.facebook.react:react-native:+" // compile -> implementation
}

关于这个问题,其他的三方库都可以按照这个规格修改,本质都是构建版本不一致问题。

react-native常见错误整理第8张

戳这里下载这都是修改好的,直接拿去用吧

-----------

12、iOSRCTWeChat接入注意事项

react-native常见错误整理第9张

react-native常见错误整理第10张13、iOSCannot set build number with plist path containing $(SRCROOT)Please remove $(SRCROOT) in your Xcode target build settings

Please remove $(SRCROOT) in your Xcode target build settings

fastlane 无法识别出$(SRCROOT)的路径,移除$(SRCROOT)/ xcode还是会找到Info.plist文件,如何按照提示只移除$(SRCROOT)那确实是找不到的

react-native常见错误整理第11张

https://stackoverflow.com/questions/49429944/cannot-find-srcroot-agvtool-increment-build-number-fastlane

The current solution to your problem would be to remove the $(SRCROOT) from your build settings. $(SRCROOT) means "directory where .xcodeproj is" so you will be perfectly fine to remove it (Xcode will still look for it relatively from the .xcodeproj).

We've recently removed agvtool from theget_version_numberaction (in version2.87.0in favor of using thexcodeprojgem where we can more nicely handle which target is found, handle $(SRCROOT), and remove that "avgtool setup process". I will be working on replacing agvtool inincrement_build_numberandget_build_numbersoon which should hopefully prevent further issues like this one.

react-native常见错误整理第10张14、Error:The minSdk version should not be declared in the android manifest file

Error:The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.

解决方案 把manifest.xml 里的sdk最小版本设置都删掉 Androidstudio3.0 以后 不能在manifest.xml 设置这些 必须在 gradle里设置

react-native常见错误整理第13张

react-native常见错误整理第10张15、Android mnifest file merging error tool:allowBackup=true

for attribute android:allowBackup, but no new value specified

这种类似问题,都是mainfest文件合并失败,建议所有mainfest.xml都加上

<applicationandroid:allowBackup="true"tools:replace="android:allowBackup">

</application>

react-native常见错误整理第10张16、Android怎么编译都不通过 gradle.properties版本变更或

修改或更新了distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip

~/.gradle 下面会有缓存,而由于删除了缓存文件导致找不到,Extenal Libraries会大片的飘红,解决方法是先移除这些依赖,再重新编译(这个问题影响了我好多天fuck)

react-native常见错误整理第16张

react-native常见错误整理第10张17、设置gradle阿里云镜像

新增文件:~/.gradle/init.gradle (全局代理一次性解决所有项目gradle被墙问题)

allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url}replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url}replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}

免责声明:文章转载自《react-native常见错误整理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇dos文件(夹)复制命令:copy和xcopydup和dup2用法小结下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Linux 环境下 node 以及 jit 的简单环境配置说明

注意事项: 1. 注意这个包需要实时更新. 2. 更新时需要按照目录覆盖文件. 3. 谁负责谁治理的态度, 有更新,需要完整的进行覆盖安装. 建议先删除旧文件, 替换新文件. 4. 为了简单起见, 直接将部署文件放到了 /nodejs 这个目录下面 1. 解压缩文件到相应的路径, 如图示 建议方法为 直接将压缩包放到 / 目录下面 执行命令 t...

Cannot find module '@babel/core'

错误信息 error in ./src/main.js Syntax Error: Error: [BABEL] F:\webstorm_space\iwts\src\main.js: Cannot find module '@babel/core'Require stack: - F:\webstorm_space\iwts\node_module...

android调试工具DDMS

DDMS工作机制    DDMS全称Dalvik Debug Monitor Service.DDMS为IDE和emultor及真正的android设备架起来了一座桥梁,Android DDMS将捕捉到终端的ID,并通过adb建立调试器,从而实现发送指令到测试终端的目的 1)每一个Android应用都运行在一个Dalvik虚拟机实例里,而每一个虚拟机实例都...

macOS 系统更新node老是不成功

 使用网上的方法,更新macOS系统上的node,总是不成功。   每次打开新的终端,node -v 都会显示之前的版本v8.11.4。。咋回事!!!     【方法】:    直接卸载 node(要卸载干净!)         但是通过 终端的命令行也难以卸载干净:MacOS X 10.10卸载Node      试了这个方法也不行:mac安装nod...

Kotlin 实战记录(一):Android Studio + Kotlin 开发问题整理

近期转向kotlin进行项目开发,途中遇到了不少IDE+配置的问题,这里会进行一一的汇总和整理问题及解决方案。 一、New Gradle Sync is not supported due to containing Kotlin modules using an unsupported plugin version 问题分析: 导致此问题的情况可能是以下...

使用阿里ARouter路由实现组件化(模块化)开发流程

Android平台中对页面、服务提供路由功能的中间件,我的目标是 —— 简单且够用。 这是阿里对Arouter的定位,那么我们一起来梳理一下Arouter使用流程,和使用中我所遇到的一些问题! 先来看看有哪些功能 模块化的要解决的问题 模块间页面跳转(路由); 模块间事件通信; 模块间服务调用; 模块的独立运行; 模块间页面跳转路由拦截(登录) 其...