將用博客來記錄自己在react native開發(fā)過程中遇到的問題,這篇主要側(cè)重于配置過程中用到的問題。這種問題可能只需要一個合適的答案,找尋這個答案可能需要花費(fèi)半天的工作時間,甚至更久。
可以在我的博客http://haiyangjiajian.com/交流更多相關(guān)內(nèi)容。
1. error: could not install smartsocket listener: Address already in use
解決方法:genymotion的adb設(shè)置Android sdk
2. cant find local.properties
解決方法:手動添加文件,然后sdk.dir=xx
3. Undefined symbols for architecture x86_64: “std::terminate()”
解決方法:I ran in to this issue as well, and the solution @charpeni proposed solved the issue. To be clear for others, if you are upgrading to 0.26+ then you need to make the following changes.
In ios/YourProject.xcodeproj/project.pbxproj, look for the two lines like OTHER_LDFLAGS = "-ObjC";. Replace them with the following:
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);
4. react-native run-android時出現(xiàn)Could not download imagepipeline.aar
解決方法:修改build.gradle的版本,com.android.tools.build:gradle:2.1.0,改為更高的,然后更改gradle/wrapper/gradle-wrapper.properties中相應(yīng)的gradle-2.10-all.zip。
5. Application ReactExample has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
解決方法: 關(guān)掉其他react-native server和node進(jìn)程
6. realm對于schema的更新需要重新啟動應(yīng)用,如果應(yīng)用已經(jīng)在本地數(shù)據(jù)庫中寫入了數(shù)據(jù),則需要將應(yīng)用刪除,重裝,因為schema和已有數(shù)據(jù)會存在沖突。
7. 自己react-native init test.然后測試realm。在ios端總是提示‘Cannot read property 'debugHosts' of undefined’ 和‘Module AppRegistry is not a registered callable module’
解決方法:是rnpm的問題,對于ios項目來說,project name中不能有excample和test,需要在packaje.json中加入。但是自己測試并沒有成功。測試將project name命名為其他可以。Realm團(tuán)隊稱在下一個版本中會修復(fù)這個問題
"rnpm": {
"ios": {
"project": "ios/<project-name>.xcodeproj"
}
}
對于andorid新建的包含realm的rn項目中還會有'Missing Realm constructor-please ensure RealmReact framework is included'的問題
解決方法是在MainApplication.java中添加如下兩行
import io.realm.react.RealmReactPackage; // ADD THIS
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RealmReactPackage() // AND THIS
);
}
如在android中出現(xiàn)“Project with path ':realm' could not be found in project ':app'. realm”的問題,則需要在setting.gradle中添加
include ':realm'
project(':realm').projectDir = new File(settingsDir, '../node_modules/realm/android')
8. react native realm的可視化
官方文檔中只介紹了Objective-C,Java,Swift中有realm的可視化工具Realm Browser(暫時只支持mac),在react native中也可以使用。
console.log(db.path);//輸出realm在模擬器上存儲的目錄
adb pull /data/data/<packagename>/files/ . //從模擬器上或者真機(jī)(需要root)拉取realm文件
用Realm Browser打開即可,默認(rèn)名字是default.realm