React Native入坑记录
1.render中如果使用props,直接用this.props.xxx,如果是在JSX中,用{this.props.xxx}
2.警告each child in an array or iterator should have a unique "key" prop.
在<PickerItem ... /> 加一个 key="";
3.组件id:增加ref="xxx".使用时this.refs.xxx.state.yyyy
4.android发布后白屏
重新生成asset
5.生成asset时报错:A problem occurred starting process 'command 'node''
先执行./gradlew --stop
6.判断系统
import {
Platform,
} from 'react-native';
console.warn(Platform.OS);
7.Android发布后闪退深坑
首先手动在android目录下创建react.grandle,内容为:
def config = project.hasProperty("react") ? project.react : [];
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
def entryFile = config.entryFile ?: "index.android.js"
// because elvis operator
def elvisFile(thing) {
return thing ? file(thing) : null;
}
def reactRoot = elvisFile(config.root) ?: file("../../")
def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?:
file("$buildDir/intermediates/assets/debug")
def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?:
file("$buildDir/intermediates/assets/release")
def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?:
file("$buildDir/intermediates/res/merged/debug")
def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?:
file("$buildDir/intermediates/res/merged/release")
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName")
def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName")
task bundleDebugJsAndAssets(type: Exec) {
// create dirs if they are not there (e.g. the "clean" task just ran)
doFirst {
jsBundleDirDebug.mkdirs()
resourcesDirDebug.mkdirs()
}
// set up inputs and outputs so gradle can cache the result
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
outputs.dir jsBundleDirDebug
outputs.dir resourcesDirDebug
// set up the call to the react-native cli
workingDir reactRoot
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
enabled config.bundleInDebug ?: false
}
task bundleReleaseJsAndAssets(type: Exec) {
// create dirs if they are not there (e.g. the "clean" task just ran)
doFirst {
jsBundleDirRelease.mkdirs()
resourcesDirRelease.mkdirs()
}
// set up inputs and outputs so gradle can cache the result
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
outputs.dir jsBundleDirRelease
outputs.dir resourcesDirRelease
// set up the call to the react-native cli
workingDir reactRoot
commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
enabled config.bundleInRelease ?: true
}
gradle.projectsEvaluated {
// hook bundleDebugJsAndAssets into the android build process
bundleDebugJsAndAssets.dependsOn mergeDebugResources
bundleDebugJsAndAssets.dependsOn mergeDebugAssets
processDebugResources.dependsOn bundleDebugJsAndAssets
// hook bundleReleaseJsAndAssets into the android build process
bundleReleaseJsAndAssets.dependsOn mergeReleaseResources
bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets
processReleaseResources.dependsOn bundleReleaseJsAndAssets
}
然后在根目录下执行:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/release/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/release
React Native入坑记录的更多相关文章
- react Native 踩坑记录
应用 1 安卓打包 经验 解决方案 ,官方 解决方案 2 调试 用 React-Native-Debugger 教程 3 微信分享和登录 使用 react-native-wechat 地址 设计 ...
- react native踩坑记录
一 .安装 1.Python2 和Java SE Development Kit (JDK)可以直接通过腾讯电脑关键安装, Android SDK安装的时候路径里不能有中文和空格 2.配置java环境 ...
- React Native之坑总结(持续更新)
React Native之坑总结(持续更新) Genymotion安装与启动 之前我用的是蓝叠(BlueStack)模拟器,跑RN程序也遇到了一些问题,都通过搜索引擎解决了,不过没有记录. 但是Blu ...
- React Native 填坑一
React Native 填坑一 关于RN的布局 分为主轴和交叉轴, 主轴可以是横向也可以是竖向,交叉轴也是对应的. 主轴默认是竖向.如果要更改用flexdirection 主轴对齐方式:justif ...
- React native采坑路 Running 1 of 1 custom shell scripts
1. Running 1 of 1 custom shell scripts 卡住的问题. 分析: 四个文件没有下载完成. boost_1_63_0.tar.gz folly-2016.09.26.0 ...
- React Native踩坑Tip
最近在使用React Native(以下简称RN)中踩了个坑,RN只能异步调用原生方法,所以在原生方法直接调用UI刷新操作需要将任务递交到主线程才可以. RCT_EXPORT_METHOD(finis ...
- React Native填坑之旅--与Native通信之iOS篇
终于开始新一篇的填坑之旅了.RN厉害的一个地方就是RN可以和Native组件通信.这个Native组件包括native的库和自定义视图,我们今天主要设计的内容是native库方面的只是.自定义视图的使 ...
- React Native填坑之旅--组件生命周期
这次我们来填React Native生命周期的坑.这一点非常重要,需要有一个清晰的认识.如果你了解Android或者iOS的话,你会非常熟悉我们今天要说的的内容. 基本上一个React Native的 ...
- React Native填坑之旅--Flow篇(番外)
flow不是React Native必会的技能,但是作为正式的产品开发优势很有必要掌握的技能之一.所以,算是RN填坑之旅系列的番外篇. Flow是一个静态的检查类型检查工具,设计之初的目的就是为了可以 ...
随机推荐
- src引入js时添加时间戳参数方法
代码如下: <script>document.write('<script src="js/judgeLogin.js?t=' + new Date().getTime() ...
- GoLang之strings、buffers、bytes、binary包
strings包 strings包的使用举例: package main import s "strings" import "fmt" var p = fmt ...
- [原]OpenGL基础教程(一)多边形绘制
1.opengl开发环境搭建 参考http://brothergrup.iteye.com/blog/1602471 2.为三角形填充颜色: 填充颜色函数为glColor(3/4)*(r,g,b) ...
- Oracle迁移至PostgreSQL工具之Ora2Pg
1. 描述 Ora2Pg是一个免费的工具,用于将Oracle数据库迁移到PostgreSQL兼容的模式.它连接您的Oracle数据库,自动扫描并提取它的结构或数据,然后生成可以装载到PostgreSQ ...
- 【ReviewBoard】安装与配置
0. 引言 环境:Ubuntu 14.04 Server(虚拟机) 这篇文章里说的是review board官方的安装方式,bitnami出了针对win/linux的集成安装包,用它可能简单点,没有尝 ...
- 10.14 预订会议室的小Demo
2018-10-14 17:12:32 越努力,越幸运.永远不要高估自己! 网上修改一下博客网站样式,做个仿qq空间的! 放上github连接 :https://github.com/TrueNewB ...
- MongoDB数据库连接失败
win10下原来一直在用的MongoDB突然连接不上了,报错如下: 解决方法是:net start MongoDB重启服务
- PHP链接MySQL,查询数据库内容,删除数据库内容。。。记住链接公式!!!
//扩展类叫MySQLi MySQL是数据库,MySQLi是扩展 Id地址本地网络服务器的地址localhost 如果想链接别人的输入他的服务器id地址. //root代表的是数据库名, //poss ...
- db2 v11 安装测试
一.准备环境: 修改/etc/hosts如下配置: #vi /etc/hosts 127.0.0.1 localhost 修改系统内核参数 # vi /etc/sysctl.conf kerne ...
- F#周报2019年第1期
新闻 介绍versionsof.net InfoQ正在寻找F#社区的声音 使用F#开发端对端的实际应用 UnoPlatform上的F# Elmish 视频及幻灯片 事件溯源DIY02--事件,事件存储 ...