Android 引入react-native-qrcode-scanner插件所碰到的问题

513 阅读1分钟

本文中所有问题的安卓环境是 “react”:”16.8.3”

“react-native”:”0.59.9”

“React-native-camera”:”^3.3.1"

undefined is not an object(evaluating '_react2.PropTypes.oneOfType’) 碰到这样的问题原因在于PropTypes的引用,react从16版本开始,已经将PropTypes功能移出来了,可以从第三方包'prop-types’中引用

解决方法:

找到目标文件中的

 import {PropTypes } from ‘react’

替换成

Import PropTypes from ‘prop-types’

再将项目中的

React.PropTypes.

替换成

PropTypes.

最后不要忘了安装prop-types包 yarn add prop-types

Could not resolve project :react-native-camera和Cannot choose between the following configurations of project :react-native-camera:

  • generalDebugRuntimeElements
  • mlkitDebugRuntimeElements

在android/app/build.gradle文件中的defaultconfig下添加

missingDimensionStrategy 'react-native-camera', 'general’

在android/build.gradle里添加

allprojects {

repositories {

maven { url "https://jitpack.io" }

maven { url "https://maven.google.com" }

    }

}

Unable toloadscript.Make sure you're either running a metro server(run 'react-nativestart' ) or thatyour bundle 'index.android.bundle' is packaged correctly for release. 项目目录/android/app/build.gradle里添加下面三个

project.ext.react = [

bundleInDebug:true,

bundleInAlpha:true,

bundleInBeta:true

]

org.gradle.api.tasks.TaskExecutionException:Exectuin failed for task

在AndroidManifest中

schemas.android.com/apk/res/and…"

xmlns:tools="schemas.android.com/tools" //添加这个

package="cn.tuniu.guide">

<application tools:node="replace//添加这个

tools:node="replace"完全替换低优先级元素

Error: Program type already present: android.support.v4.app.INotificationSideChannel 向gradle.properties添加以下内容:

android.enableJetifier=true

android.useAndroidX=true

android.app.Application cannot be cast to com.facebook.react.ReactApplication 在AndroidManifest.xml文件中添加

<application

  android:name=".MainApplication”

跟multiDex有关的问题 在app的build.gradle的defaultconfig中添加

multiDexEnabled : true

跟V4有关的问题 在app的build.gradle的dependencies中添加

implementation'com.android.support:support-v4:28.0.0'

以此记录引入react-native-camera插件碰到的问题,iOS端并没有任何报错,Android端不熟悉,花了本人两天时间