如何在React Native App中添加条形码扫描仪?

问题描述

我正在为我的应用程序使用react-native-cli ...我正在尝试添加条形码,但没有成功。

这是我用于条形码扫描仪的代码...

import React,{
  Component
} from 'react';
import { ToastAndroid,AppRegistry } from 'react-native';
import BarcodeScanner from 'react-native-barcodescanner';

class BarcodeScannerExampleApp extends Component {
  constructor(props) {
    super(props);

    this.state = {
        playBeep: "on",vibrate: "on",bulkScan : "on",};
  }

  barcodeReceived(e) {
    console.log('Barcode: ' + e.data);
    console.log('Type: ' + e.type);
    ToastAndroid.show(('Barcode: ' + e.data + ',Type:' + e.type),ToastAndroid.SHORT);
  }

  render() {
    return (
      <BarcodeScanner
        onBarCodeRead={this.barcodeReceived}
        style={{ flex: 1 }}
        playBeep={this.state.playBeep}
        vibrate={this.state.vibrate}
        bulkScan={this.state.bulkScan}
      />
    );
  }
}

AppRegistry.registerComponent('BarcodeScannerExampleApp',() => BarcodeScannerExampleApp);

错误

> Configure project :react-native-barcodescanner
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored,as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.5.3.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning,remove "buildToolsversion '23.0.1'" from your build.gradle file,as each version of the Android Gradle Plugin Now has a default version of the build tools.

> Task :react-native-barcodescanner:compileDebugJavaWithJavac Failed

Deprecated Gradle features were used in this build,making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
31 actionable tasks: 31 executed
C:\Users\Hp\Desktop\Final Project\barcode\node_modules\react-native-barcodescanner\android\src\main\java\com\eguma\barcodescanner\BarcodeScannerPackage.java:20: error: method does not override or implement a method from a supertype
    @Override
    ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':react-native-barcodescanner:compileDebugJavaWithJavac'.
> Compilation Failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD Failed in 38s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command Failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
C:\Users\Hp\Desktop\Final Project\barcode\node_modules\react-native-barcodescanner\android\src\main\java\com\eguma\barcodescanner\BarcodeScannerPackage.java:20: error: method does not override or implement a method from a supertype

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)