博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
React Native入坑记录
阅读量:5154 次
发布时间:2019-06-13

本文共 3678 字,大约阅读时间需要 12 分钟。

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 operatordef 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

转载于:https://www.cnblogs.com/punkrocker/p/6373127.html

你可能感兴趣的文章
解决Ubuntu下博通网卡驱动问题
查看>>
【bzoj2788】Festival
查看>>
执行gem install dryrun错误
查看>>
Java SE之正则表达式一:概述
查看>>
HTML5简单入门系列(四)
查看>>
实现字符串反转
查看>>
转载:《TypeScript 中文入门教程》 5、命名空间和模块
查看>>
苹果开发中常用英语单词
查看>>
[USACO 1.4.3]等差数列
查看>>
Shader Overview
查看>>
Reveal 配置与使用
查看>>
Java中反射的学习与理解(一)
查看>>
C语言初学 俩数相除问题
查看>>
B/S和C/S架构的区别
查看>>
[Java] Java record
查看>>
jQuery - 控制元素显示、隐藏、切换、滑动的方法
查看>>
postgresql学习文档
查看>>
Struts2返回JSON数据的具体应用范例
查看>>
js深度克隆对象、数组
查看>>
socket阻塞与非阻塞,同步与异步
查看>>