如何嵌入: 参考 react native 学习笔记—-将react native嵌入到Android原生应用 Android原生嵌入React Native 过程中遇见的各种坑 在Android原生中嵌入React Native,进而React Native调用原生
compile 'com.facebook.react:react-native:+
问题:
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (3.0.0) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.解决: 在app的gradle文件中添加以下代码
configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0' }添加权限判断
if (Build.VERSION.SDK_INT >= 23) { if(!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); startActivity(intent); return; } else { //绘ui代码, 这里说明6.0系统已经有权限了 Intent intent = new Intent(MainActivity.this,MyReactActivity.class); startActivity(intent); } } else { //绘ui代码,这里android6.0以下的系统直接绘出即可 Intent intent = new Intent(MainActivity.this,MyReactActivity.class); startActivity(intent); }原因:js中封装的对应js缺少基础的属性 如下 添加 …View.propTypes,
'use strict'; import { PropTypes } from 'react'; import { requireNativeComponent, View } from 'react-native'; var iface = { name: 'MGWebView', propTypes: { url: PropTypes.string, html: PropTypes.string, ...View.propTypes, }, }; module.exports = requireNativeComponent('MGWebView', iface);