
常見(jiàn)錯(cuò)誤錦集:http://www.cnblogs.com/lovesong/p/5679340.html
ListView下拉刷新和上拉加載數(shù)據(jù):
http://lib.csdn.net/article/reactnative/40078
http://www.itdecent.cn/p/dff750d8c425
http://div.io/topic/1453
熱更新:
https://github.com/crazycodeboy/RNStudyNotes/
https://github.com/crazycodeboy/RNStudyNotes/tree/master/React%20Native%E5%BA%94%E7%94%A8%E9%83%A8%E7%BD%B2%E3%80%81%E7%83%AD%E6%9B%B4%E6%96%B0-CodePush%E6%9C%80%E6%96%B0%E9%9B%86%E6%88%90%E6%80%BB%E7%BB%93
http://blog.csdn.net/dongdong230/article/details/52625157
http://blog.csdn.net/goodchangyong/article/details/51323918
icon和啟動(dòng)頁(yè)圖片
http://www.cnblogs.com/allenxieyusheng/p/5804023.html
鍵盤遮擋輸入框問(wèn)題
http://www.cnblogs.com/pofabs/p/5109021.html
1.ReactNative 導(dǎo)入React包
importReact, {Component}from'react';
import{
AppRegistry,
Platform,//此處不可加Component 會(huì)報(bào)錯(cuò)
TouchableOpacity,
StyleSheet,
Navigator,
View,
Text
} from'react-native';
import Splashfrom'./Splash';
報(bào)錯(cuò)如下:

2.初始化state
ES5中,和屬性初始化類似
var ES5Syntax = React.createClass({
getInitialState: function() {
return {esVersion: `${this.[props.name](http://props.name/)} v1.0`,
clickCounts: 0,
};
},
});
ES6中 ,有兩種寫法:
export default class ES6Syntax extends Component { state = { esVersion: `${this.[props.name](http://props.name/)} v1.0`, clickCounts: 0, }; });
在構(gòu)造函數(shù)中對(duì)state初始化:
export default class ES6Syntax extends Component { constructor(props) { super(props); // Operations usually carried out in componentWillMount go here this.state = { esVersion: `${this.[props.name](http://props.name/)} v1.0`, clickCounts: 0, }; }; };
備注:采用ES5初始化方法會(huì)報(bào)錯(cuò),如下:

3.RN圖片有時(shí)在父元素有絕對(duì)定位時(shí),點(diǎn)擊事件會(huì)失效(具體原因不知),可通過(guò)給圖片加子元素,然后給子元素綁定點(diǎn)擊事件。
4.安卓真機(jī)調(diào)試(搖晃手機(jī)或輸入adb shell input keyevent 82)
com.android.ddmlib.InstallException: Unable to upload some APKs
(坑死人?。。。。。?br> 修改:
com.android.tools.build:gradleversion from1.3.1to1.2.3inbuild.gradlefile.
buildscript{repositories{jcenter()}dependencies{classpath'com.android.tools.build:gradle:1.2.3'}}
5.掃碼成功之后回傳掃碼結(jié)果——萬(wàn)年坑
先大致說(shuō)一下事情的起因,,,
類似微星、支付寶的掃碼功能很常見(jiàn),所以我們當(dāng)然也不甘落后,人家有的,我們也當(dāng)然得有;人家沒(méi)有的,我們最好也有;
a.掃碼跳回上一個(gè)頁(yè)面之后,主頁(yè)面下面有30%左右的黑色區(qū)域覆蓋,且上一個(gè)頁(yè)面的按鈕操作是存在的,只是被覆蓋,具體原因不詳,估計(jì)具體原因應(yīng)該是攝像機(jī)未釋放(后來(lái)經(jīng)過(guò)多方查找資料,的確是攝像頭未釋放)。
——解決方案,給BarScanner加樣式:backgroundColor:'rgba(0,0,0,.1)'
onBarCodeRead={(e)=> {
this._barcodeReceived(e)
}}
style={{flex:1,backgroundColor:'rgba(0,0,0,.1)'}}
tourchMode={this.state.torchMode}
cameraType={this.state.cameraType}
6.導(dǎo)航條控件,注意大小寫,大寫會(huì)報(bào)錯(cuò)

7.打包apk時(shí)build.gradle文件配置——圖片不顯示問(wèn)題
在模擬器時(shí)有時(shí)運(yùn)行出錯(cuò),需要將:
build script {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
里面的1.3.1改成1.2.3即可。
但是,但是,但是,在打包簽名apk時(shí),
一定要將1.2.3改回1.3.1
一定要將1.2.3改回1.3.1
一定要將1.2.3改回1.3.1
因?yàn)樵缙谝驗(yàn)榘姹締?wèn)題(不知是安卓環(huán)境還是RN環(huán)境,會(huì)導(dǎo)致圖片無(wú)法打包到apk
里面,但是APP正常運(yùn)行,只是所有圖片都不顯示,也不會(huì)報(bào)錯(cuò))
備注:要時(shí)刻注意RN版本問(wèn)題,RN官方文檔更新較快,經(jīng)常會(huì)發(fā)布新的版本。
升級(jí)本地RN查看官方文檔:http://reactnative.cn/docs/0.39/upgrading.html
安卓打包命令:./gradlew assembleRelease
8.使用React-native run-Android”命令運(yùn)行android應(yīng)用時(shí),如果常常出現(xiàn)如下錯(cuò)誤:
Starting the app (/home/xxx/soft/sdk//platform-tools/adb shell am start -n xxx/.MainActivity)…
Starting: Intent { cmp=xxx/.MainActivity }
Error type 3
Error: Activity class {xxx/xxx.MainActivity} does not exist.
盡管該應(yīng)用可以安裝到你的安卓設(shè)備, 不影響使用,但是看著好礙眼。本著不能規(guī)避問(wèn)題的原則,還是要想辦法消掉這個(gè)錯(cuò)誤。經(jīng)過(guò)本人的一番嘗試,總算解決了這個(gè)礙眼的bug.在此記錄一下解決的步驟。
- 首先是檢查這個(gè)MainActivity.Java是不是真的存在,且包名和路徑無(wú)誤;
- 如果文件存在,且包名和路徑?jīng)]有問(wèn)題,那么就打開(kāi)你項(xiàng)目所在 的/android/app/build.gradle文件,刪除defaultConfig下的applicationId,像下面這樣:
apply plugin: ‘com.android.application’
android {
compileSdkVersion xxx
buildToolsVersion “xxx”
defaultConfig {
// applicationId “xxx”
}
或者將applicationId的值改成manifest文件里指定的package。
再運(yùn)行”react-native run-android”,OK了。
出現(xiàn)這個(gè)問(wèn)題的原因是你的package和applicationId不一致。如果你沒(méi)有在你的 build.gradle 文件中定義 applicationId,這個(gè)applicationId 將默認(rèn)為 AndroidManifest.xml 中所指定的與package相同的值。
注意:現(xiàn)在的Android Gradle編譯系統(tǒng)的android項(xiàng)目是以applicationId作為唯一標(biāo)識(shí)應(yīng)用的包名。
9.安卓禁止屏幕旋轉(zhuǎn)
reactnative控件:https://github.com/yamill/react-native-orientation(我測(cè)試不管用)
在一些特殊的情況下,Android開(kāi)發(fā)期間會(huì)禁止某些Activity的橫豎屏切換.下面介紹一種簡(jiǎn)單的方法: 只要在AndroidManifest.xml里面配置一下就可以了。 在AndroidManifest.xml的activity(需要禁止轉(zhuǎn)向的activity)配置中加入 android:screenOrientation=”landscape”屬性即可(landscape是橫向,portrait是縱向)。
例如:
android:name=".DemoActivityt"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
另外,android中每次屏幕方向切換時(shí)都會(huì)重啟Activity,所以應(yīng)該在Activity銷毀前保存當(dāng)前活動(dòng)的狀態(tài),在Activity再次Create的時(shí)候載入配置。要避免在轉(zhuǎn)屏?xí)r重啟activity,可以通過(guò)在androidmanifest.xml文件中重新定義方向(給每個(gè)activity加上android:configChanges=”keyboardHidden|orientation”屬性),并根據(jù)Activity的重寫onConfigurationChanged(Configuration newConfig)方法來(lái)控制,這樣在轉(zhuǎn)屏?xí)r就不會(huì)重啟activity了,而是會(huì)去調(diào)用onConfigurationChanged(Configuration newConfig)這個(gè)方法。
尊重原創(chuàng):http://www.open-open.com/lib/view/open1328278861750.html
10.Android肯定切換端口
看了網(wǎng)上好多的資料,介紹的都是iOS切換React Native端口,然后就想Android肯定也可以切換端口。仔細(xì)看了下源代碼,試了下確實(shí)可以。源代碼就不做詳細(xì)介紹了,有興趣的話,自己去下下來(lái)看看。
先講下,這里說(shuō)的端口8081 是facebook寫死的,是打的在線包。離線包就不用通過(guò)端口,連接電腦和手機(jī)了。
說(shuō)下切換端口的步驟:
很簡(jiǎn)單,比如切換8089端口。
代碼中在application或者主activity中做如下設(shè)置:
@OverridepublicvoidonCreate() {super.onCreate(); mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mPreferences.edit().putString("debug_http_host","localhost:8089").commit(); }
為什么要在sharepreference中加”debug_http_host” ,看看android的源碼就知道了,不細(xì)講了,fb也是這么寫的。
然后在項(xiàng)目根目錄下執(zhí)行:
adb reverse tcp:8089 tcp:8089
React-native start –port 8089
好了 運(yùn)行項(xiàng)目,reload js ,手機(jī)就橋接到8089了。
ios切換端口比android簡(jiǎn)單,修改配置文件就好了,網(wǎng)上一堆,不細(xì)講了。
11.坑死人之安卓二維碼掃碼——react-native-barcodescanner
安卓二維碼掃碼之后第二次進(jìn)入或者手機(jī)鎖屏或黑屏之后,再次打開(kāi)二維碼掃碼出現(xiàn)黑屏情況。
https://github.com/ideacreation/react-native-barcodescanner/pull/61
對(duì)比修改CameraManager.java 和CameraPreview.java文件。
12.熱更新Pushy,[http://update.reactnative.cn/dashboard/5672/version](http://update.reactnative.cn/dashboard/5672/version)
13.http://www.open-open.com/lib/view/open1452907915823.htm
注意pandroid是p android
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
14.安卓實(shí)體返回鍵[http://www.zhimengzhe.com/Androidkaifa/48187.html]
(http://www.zhimengzhe.com/Androidkaifa/48187.html)
15.安卓啟動(dòng)白屏(1-3秒,根據(jù)機(jī)型CPU能力而不同)
安卓啟動(dòng)會(huì)有兩種白屏,一種是RN機(jī)制導(dǎo)致的android和IOS都有:
針對(duì)RN渲染機(jī)制導(dǎo)致的白屏問(wèn)題,可用如下方式解決,
RN機(jī)制導(dǎo)致的用如下方式解決(也可以自己更改原生代碼),但我覺(jué)得這種方式對(duì)于我這種原生開(kāi)發(fā)小白來(lái)說(shuō)更簡(jiǎn)單:
https://github.com/crazycodeboy/react-native-splash-screen
然而,凡是總會(huì)出現(xiàn)意外
按著官方文檔配置好之后,還需做如下更改
首先,MainActivity要添加如下代碼,否則會(huì)報(bào)錯(cuò):
import android.os.Bundle;
import com.cboy.rn.splashscreen.SplashScreen;

然后,增加如下目錄和文件
layout目錄用于存放樣式配置文件,drawable-xxhdpi用于存放啟動(dòng)頁(yè)圖片:

針對(duì)android自身原因?qū)е碌陌灼量捎萌缦路绞浇鉀Q,參考文章:http://www.itdecent.cn/p/6917e536de27
第一步:創(chuàng)建一個(gè)透明主題。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<!--設(shè)置透明背景-->
<item name="android:windowIsTranslucent">true</item>
</style>
第二步:在AndroidManifest.xml中為application應(yīng)用主題。
<application android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
使用react-native-maps(0.14.0)時(shí),真機(jī)運(yùn)行總是報(bào)錯(cuò),
Project react-native-maps: provided dependencies can only be jars. com.facebook.react:react-native:aar:0.44.0 is an Android Library.
:react-native-maps:prepareReleaseDependencies FAILED
進(jìn)入路徑:項(xiàng)目 --> node_modules --> react-native-maps -->lib--> android --> build.gradle,修改:
dependencies {
provided "com.facebook.react:react-native:+"
...
}
為:
dependencies {
compile "com.facebook.react:react-native:+"
...
}
參考文章:http://stackoverflow.com/questions/28774667/provided-dependencies-can-only-be-jars