如何将 ZXing 库集成到 Android Studio 进行条码扫描? [英] How to integrate ZXing Library to Android Studio for Barcode Scanning?

查看:49
本文介绍了如何将 ZXing 库集成到 Android Studio 进行条码扫描?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在互联网上寻找如何将 zxing 库包含到我的项目中,我发现了这个教程:http://blog.dihaw.com/integrating-zxing-in-your-android-app-as-standalone-scanner/

I've been looking all over internet how to include zxing library to my project, and I found this tutorial: http://blog.dihaw.com/integrating-zxing-in-your-android-app-as-standalone-scanner/

但是当我到达需要检查 BeepManager 以添加 R 导入的地步时,我的项目(即使在 MainActivity 上)中出现各种错误,无法找到 R.

But when I reach the point that you need to check for BeepManager to add the R import I get all kinds of errors in my project (Even on the MainActivity) that it couldn't find R.

我也找到了这个https://github.com/journeyapps/zxing-android-embedded/blob/master/README.md 这似乎要容易得多,因为它是由 gradle 自动集成的,但是当我同步它时会弹出一个错误,它找不到文件.

Also I found this one https://github.com/journeyapps/zxing-android-embedded/blob/master/README.md which seemed a lot easier because it was auto integrated by gradle, but when I sync it pops an error that it couldn't find the files.

任何帮助将不胜感激 :) 我是 Android Studio 的新手.

Any help would be appreciated :) I'm new to Android Studio.

我将第二种方法的设置(带有 gradle 设置的那个)添加到我的 build.gradle 并弹出 4 个错误:

I added the settings of the 2nd method (the one with the gradle settings) to my build.gradle and 4 error pop up:

Error:Failed to find: com.embarkmobile:zxing-android-legacy:2.0.0 
Error:Failed to find: com.google.zxing:core:3.0.1 
Error:Failed to find: com.embarkmobile:zxing-android-integration:2.0.0 
Error:Failed to find: com.embarkmobile:zxing-android-minimal:2.0.0

有什么帮助吗?

---答案---

  • Android Studio 的设置>Gradle>取消勾选离线工作"

推荐答案

您需要将以下内容添加到您的 build.gradle 文件中:

You need add the following to your build.gradle file:

repositories {
    mavenCentral()

    maven {
        url "http://dl.bintray.com/journeyapps/maven"
    }
}

dependencies {
    // Supports Android 4.0.3 and later (API level 15)
    compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
    compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'

    // Convenience library to launch the scanning and encoding Activities.
    // It automatically picks the best scanning library from the above two, depending on the
    // Android version and what is available.
    compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
    // This mostly affects encoding, but you should test if you plan to support these versions.
    // Older versions e.g. 2.2 may also work if you need support for older Android versions.
    compile 'com.google.zxing:core:3.0.1'
}

我的 build.gradle 文件如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.myapplication2"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    // Supports Android 4.0.3 and later (API level 15)
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
    compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'

    // Convenience library to launch the scanning and encoding Activities.
    // It automatically picks the best scanning library from the above two, depending on the
    // Android version and what is available.
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
    // This mostly affects encoding, but you should test if you plan to support these versions.
    // Older versions e.g. 2.2 may also work if you need support for older Android versions.
    compile 'com.google.zxing:core:3.0.1'
}

代码在这里.

另外,关于如何使用它,请参考我在 Stackoverflow 上的回答这里

Also, for how to use it, please refer my answer on the Stackoverflow here

它包含我测试过的方法和简单代码.

It contains method and also simple code that I have tested.

这篇关于如何将 ZXing 库集成到 Android Studio 进行条码扫描?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆