- android项目集成react native后,真机调试,如果进入react native界面崩溃,可以尝试以下命令:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
- 真机调试
将
NSURL *jsCodeLocation = [NSURL URLWithString:@"localhost/index.ios.bundle?platform=ios"];
改成:
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://192.168.199.111:8081/index.ios.bundle?platform=ios"];
并开启dev server。
- 离线包
在根目录下面执行(入口文件路径和名字根据实际情况修改):
react-native bundle --entry-file ReactComponent/index.js --bundle-output index.ios.jsbundle --platform ios --dev false --assets-dest ./
将生成的main.jsbundle和assets加入到Xcode中(添加引用)
在代码中改成:
NSURL *jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
react-native bundle --entry-file index.ios.js --bundle-output main.jsbundle --platform ios --dev false --assets-dest ./
- 如果执行了react-native link后,运行ios提示
native module can not be null
检查一下cocoapods中的react native库的引用
#'node_modules'目录一般位于根目录中
# 但是如果你的结构不同,那你就要根据实际路径修改下面的`:path`
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTText',
'RCTImage',
'RCTLinkingIOS',
'RCTSettings',
'RCTVibration',
'RCTActionSheet',
'RCTNetwork',
'RCTWebSocket', # 这个模块是用于调试功能的
# 在这里继续添加你所需要的模块
]
# 如果你的RN版本 >= 0.42.0,请加入下面这行
pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
- Unrecognized font family ionicons
Cannot read property 'UIAppFonts' of null
参考:
https://www.npmjs.com/package/react-native-vector-icons
按照链接里面的步骤,采用cocoapods来进行修改
第一步:在cocoapods中加入RNVecorIcons的引用;
第二部:修改info.plist,加入字体的声明
- FAILURE: Build failed with an exception.
- What went wrong:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugApk'.
A problem occurred configuring project ':react-native-vector-icons'.
The SDK Build Tools revision (23.0.1) is too low for project ':react-native-vector-icons'. Minimum required is 25.0.0
修改android/build.gradle中的
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
为
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
- Error:The SDK Build Tools revision (23.0.3) is too low for project ':app'. Minimum required is 25.0.0
在android/build.gradle中进行设置
(参考:
https://github.com/oblador/react-native-vector-icons/issues/428、
http://stackoverflow.com/questions/41890659/errorthe-sdk-build-tools-revision-23-0-3-is-too-low-for-project-app-minim)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
}
}
如果不行的话,试试清除缓存。
-
向原生工程中引入react-native-vector-icons库的步骤
参考:https://www.npmjs.com/package/react-native-vector-icons -
警告:
Animated: 'useNativeDriver' is not supported because the native animated module is missing. Failing back to JS-based animation. .....
这个问题和iOS端相关,需要在cocoapods中,加入RCTAnimation的引用,类似于下:
# 'node_modules'目录一般位于根目录中
# 但是如果你的结构不同,那你就要根据实际路径修改下面的`:path`
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTAnimation',
'RCTText',
'RCTImage',
'RCTLinkingIOS',
'RCTSettings',
'RCTVibration',
'RCTActionSheet',
'RCTNetwork',
'RCTWebSocket', # 这个模块是用于调试功能的
# 在这里继续添加你所需要的模块
]
# 如果你的RN版本 >= 0.42.0,请加入下面这行
pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
- Deviceinfo native modules is not installed correctly
检查iOS工程,0.42的react native中有RCTConvert+Map这个文件,而0.44的版本中有这个文件,如果iOS工程中是用Cocoapods来管理第三方库的话,那么需要执行 pod update更新一下。
- [iOS][cocoapods] 'RCTAnimation/RCTValueAnimatedNode.h' file not found
参考链接:https://github.com/facebook/react-native/issues/13198
需要在报错的文件中,修改RCTValueAnimatedNode.h的引用方式,从尖括号改成双引号:
#import "RCTValueAnimatedNode.h"
- TaskQueue: Error with task : No item for index 0
解决方法:
在使用数组的map方法时,要给每条数据加一个唯一key的键,并且要return一下,正确写法如下:
if(json.data.list &&
json.data.list.length > 0){
if(this._requestGradeList_para.pagesize === 1){
this.teacherGradeListStore.initialList(json.data.list.map( (item)=>{
item["key"] = item.student_id;
return item;
}));
}else{
this.teacherGradeListStore.concatList(json.data.list.map( (item)=>{
item["key"] = item.student_id;
return item;
}));
- 集成图标第三方库“react-native-charts-wrapper”的步骤和方法
解决方法:参考链接:http://blog.csdn.net/sinat_17775997/article/details/67635156
- Warning: In next release empty section headers will be rendered. In this release you can use 'enableEmptySections' flag to render empty section headers.
解决方法:
这个错误出现在ListView中,在以后的版本中才会实现空的section headers作为默认值,当前版本并没有支持。
如果我们不需要使用headers的话,可以禁止EmptySections。
解决方法:
<ListView
style={styles.listView}
dataSource={this.state.dataSource}
enableEmptySections={true}
/>