Android使用React Native 出现的问题

如何嵌入:
参考
react native 学习笔记—-将react native嵌入到Android原生应用
Android原生嵌入React Native 过程中遇见的各种坑
在Android原生中嵌入React Native,进而React Native调用原生

一、原生Android嵌入React Native出现问题

1. 添加以下配置时出现的问题

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'
    }

2.android 6.0 会出现权限问题调试

android 6.0 permission denied for this window type

添加权限判断

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);
        }

二、使用原生组件出现的问题

1.

`MGWebView` has no propType for native prop `MGWebView.accessibilityLabel` of native type `String`
If you haven't changed this prop yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.

原因: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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值