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

查看:2089
本文介绍了如何将ZXing Library集成到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 ,看起来容易多了,因为它是由毕业生自动集成的,但是当我同步它会弹出一个找不到文件的错误。

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.

编辑:

我添加了设置第二种方法(具有渐变设置的)到我的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

任何帮助?

--- ANSWER ---

---ANSWER---

要解决此问题,我需要在Gradle上禁用Offline Work。进入Android Studio的设置> Gradle>取消选中'离线工作'
之后,你很好去!

To fix this problem I needed to disable Offline Work on Gradle. Go into Android Studio's settings>Gradle>Uncheck 'offline work' After that, you're good to go!

推荐答案

p>您需要在 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 Library集成到Android Studio进行条形码扫描?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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