Android使用React Native 出现的问题

    xiaoxiao2022-06-24  31

    如何嵌入: 参考 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);
    转载请注明原文地址: https://ju.6miu.com/read-1123796.html

    最新回复(0)