Android 工程整合React Native 0.44 注意點,androidreact

來源:互聯網
上載者:User

Android 工程整合React Native 0.44 注意點,androidreact

當前(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 進行混合開發教程 可供參考。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.