Android 工程集成React Native 0.44 注意點


當前(2017年5月22日 )React Native開發相當火爆,但是搜索下來,沒有最新版本0.44集成的教程,因此嘗試了一下如何集成到Android原生工程中去。本篇旨在記錄出現的問題以及應對方式。

一、集成的過程比較簡單,按照教程一步一步來即可:

中文版教程:http://reactnative.cn/docs/0.44/integration-with-existing-apps.html#content

英文版教程:http://facebook.github.io/react-native/docs/integration-with-existing-apps.html

 

二、按照上述教程集成完畢后,運行出現錯誤:

1、Error:Conflict with dependency 'com.google.code.findbugs:jsr305'

——這個stackoverflow有解答,筆者采用的解決方式是在app的build.gradle中添加 androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'。

 

2、java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule'

——本問題在facebook的issue中也有提及以及6152,需要修改support包版本至23.0.1:compile 'com.android.support:appcompat-v7:23.0.1' 以及compile 'com.android.support:design:23.0.1'。以及gradle.properties (在文件末尾添加,android.useDeprecatedNdk=true)。注意此處修改之后,布局文件中的Image屬性app:srcCompat將不會識別,換為android:src即可。解決過程參考自https://github.com/Kennytian/embedded第6點。

 

3、Unable to resolve module `react/lib/ReactDebugCurrentFrame`  或者 Unable to resolve module `react/lib/ReactComponentWithPureRenderMixin`

——此處需要注意在按照教程安裝完畢時,可能會有類似的信息‘npm WARN react-native@0.44.0 requires a peer of react@~16.0.0-alpha.6 but none was installed.’ 搜索一下得知,npm install --save react react-native 會使得安裝版本不匹配,可運行如下命令:npm install --save react@16.0.0-alpha.6 react-native

 

4、Can't find variable: __fbBatchedBridge

——主要檢查一下npm start是否成功運行,或者嘗試 adb reverse tcp:8081 tcp:8081。如果繼續出錯,可參考這里

 

5、檢查一下android工程的external libraries下的react native版本是不是0.44:如果不是,請修改

 maven {
            `url "$rootDir/../node_modules/react-native/android"`//地址是否正確 } 修改url "$rootDir*/..*/node_modules/react-native/android"為url "$rootDir/node_modules/react-native/android" (來自簡書

 

附送 史上最詳細的Android原生APP中添加ReactNative 進行混合開發教程 可供參考。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM