剛開始接觸react-native小白一個(gè)骇吭,據(jù)說react可以跨平臺(tái)就拿來試一下橙弱,結(jié)果不試不知道,一試全是坑T镎棘脐!特此記錄一些沒有baidu到太好的解決方案的坑,即大家都懂的A隆蛀缝!
1、React Native version mismatch(Android)
本來用的好好的目代,突然就變成這個(gè)樣子了屈梁,這是因?yàn)锳ndroid studio 選取了最新的react native版本嗤练,詳見build.gradle,你會(huì)發(fā)現(xiàn)這樣幾行配置:
dependencies {
? ? compile fileTree(dir: "libs", include: ["*.jar"])
? ? compile "com.android.support:appcompat-v7:23.0.1"
? ? compile "com.facebook.react:react-native:+"? // From node_modules
}
問題就出現(xiàn)在?compile "com.facebook.react:react-native:+"這一行在讶,所以只要把版本改為你使用的版本號就可以了煞抬,如下:
dependencies {
? ? compile fileTree(dir: "libs", include: ["*.jar"])
? ? compile "com.android.support:appcompat-v7:23.0.1"
? ? compile ("com.facebook.react:react-native:0.51.0") { force = true } // From node_modules
}
2、error Received malformed response from registry for undefined. The registry may be down.
刪除yarn构哺,刪除方法:cd /usr/local/bin?? rm yarn
3革答、Unexpected end of JSON input while parsing near...
npm config set registry http://registry.cnpmjs.org 將淘寶的代理設(shè)回去,不要用淘寶代理就好曙强,原因未知残拐。
4、RN:0.55旗扑,IOS真機(jī)設(shè)備無法連接進(jìn)行調(diào)試蹦骑,會(huì)報(bào)錯(cuò):"Remote JS Debugger"-option gives"Connection timed out" on real device (iOS) ,但是在模擬器上可以
引起這個(gè)問題的原因可能是和IOS證書綁定的APPID有關(guān)系臀防,不要使用XCODE自動(dòng)生成APPID的方式眠菇,使用現(xiàn)有(或是重新新建證書并綁定APPID)證書已存在的APPID進(jìn)行簽名,即Bundle Identifier填寫所使用的簽名 證書中存在的APPID袱衷,然后重新編譯即可
5捎废、Can't find variable: Symbol
在使用mobx進(jìn)行數(shù)據(jù)管理時(shí),有一版會(huì)有Can't find variable: Symbol 這種問題致燥,最后發(fā)現(xiàn)是mobx版本問題登疗,最后將"mobx": "^4.1.0","mobx-react": "^5.0.0",設(shè)定為這兩個(gè)版本
6、React-Native 與IOS通信嫌蚤,之傳遞參數(shù)
只說一下怎么傳遞NSDictionary:
RCT_EXPORT_MODULE();
RCT_REMAP_METHOD(GetCSVFileContent,
?? ? ? ? ? ? ? ? paramater:(NSDictionary*)param
?? ? ? ? ? ? ? ? resoler:(RCTPromiseResolveBlock)resolve
?? ? ? ? ? ? ? ? rejecter:(RCTPromiseRejectBlock)reject)
{? }
7辐益、React-Native與Android通信,之傳遞參數(shù)
@ReactMethod
public void GetCSVFileContent(ReadableMap param, Promise promise)
{
String year = param.getString("year");
String month = param.getString("month");
String type = param.getString("type");
System.out.println("year="+year+"month="+month+"type="+type);
/*
HashMap newMap =
Iterator iter = newMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
System.out.println("收到的參數(shù)key="+key+"value="+val);
}
*/
}
8脱吱、react-navigation在Android中headerTitle不居中的問題("react-navigation": "^1.5.7")
經(jīng)查閱資料需要修改兩個(gè)地方:
一智政、react-navigation/src/header/header.js
if (Platform.OS ==='android') {
if (!options.hasLeftComponent) {
// style.left = 0;
? }
if (!options.hasRightComponent) {
//style.right = 0;
? }
}
二、react-navigation/src/header/header.js
justifyContent: Platform.OS ==='ios' ?'center' :'center'
都修改為以上就可以了
9箱蝠、React Native version mismatch(IOS)
我是因?yàn)榇蜷_了之前運(yùn)行了的shell窗口续捂,導(dǎo)致出現(xiàn)在IOS中,解決方法就是關(guān)掉所有shell窗口宦搬,重新執(zhí)行run-ios