如何将ZXING导入android studio? [英] How to import ZXING to android studio?

查看:61
本文介绍了如何将ZXING导入android studio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用安卓工作室我想在我的应用程序中导入'ZXING',我找了很多文章,找到了以下站点

I use android studio I want to import 'ZXING' in my application, I find many articles and found the following site

https://github.com/zxing/zxing/

我下载了ZIP并解压,并找到了一些教程但是好像没有说的太详细了,需要导入什么?实现二维码扫描

I downloaded the ZIP and unzip, and find some tutorials But it does not seem to be too detailed about the details, what I need to import? To achieve QRCode scan

我还是不知道怎么做

4/14我试过提供的列侬 URLzxing-android-minimal"并导入'gradle-wrapper.jar'

4/14 I tried Lennon URL provided "zxing-android-minimal" And import the 'gradle-wrapper.jar'

但是当我写新的 IntentIntegrator (this) .initiateScan();仍然出现无法解析符号'IntentIntegrator"消息

But when I wrote new IntentIntegrator (this) .initiateScan (); Still appear "Can not resolve symbol 'IntentIntegrator" message

https://www.dropbox.com/s/2srga9iq75iqe4m/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96%202015-04-10%2001.33.56.png?dl=0

我确实有一个正确的 '.jar 选择 Add As Library但是出现错误时,他好像没有加

I do have a right '.jar select Add As Library But when an error occurs, he does not seem to be added

4/10

终于不再出现无法解析符号'IntentIntegrator"这是代码,我哪里错了?

Finally no longer appear "Can not resolve symbol 'IntentIntegrator" this is the code,What do I wrong?

我删除了新的 IntentIntegrator (this) .initiateScan();'应用程序正常运行

I removed the new IntentIntegrator (this) .initiateScan (); 'applications normal operation

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new IntentIntegrator(this).initiateScan();
}

我的'build.gradle'

my 'build.greadle'

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

推荐答案

当我使用 zxing 库开发我的应用程序时,我遇到了很多麻烦.所以看看这个 zxing 最小:https://github.com/Promptus/zxing-android-minimal/树/主

I had many troubles when I developed my app using zxing library. So take a look this zxing minimal: https://github.com/Promptus/zxing-android-minimal/tree/master

它对我来说效果很好,而且更容易实现.

It worked perfectly to me and was easier to implement.

在你的项目中打开这个文件:

Open up this file in your project:

/gradle/wrapper/gradle-wrapper.properties

/gradle/wrapper/gradle-wrapper.properties

编辑 distributionUrl 行并设置它:

Edit the distributionUrl line and set it too:

distributionUrl=http://services.gradle.org/distributions/gradle-1.8-all.zip重建您的项目.

distributionUrl=http://services.gradle.org/distributions/gradle-1.8-all.zip Rebuild your project.

更新:您现在可能想要使用 gradle-2.1-all.zip.

Update: You might want to use gradle-2.1-all.zip now.

首先,您必须删除您的 libs 文件.然后你必须删除

First of all, you must remove your libs file. Then you have to remove

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

来自 MyApplicationbuild.gradle,因为该 gradle 是针对整个项目的,最好在每个模块中使用它.

from your build.gradle of MyApplication, because that gradle is for the whole project, and it's better you use it in each module.

之后,打开app模块的build.gradle,添加如下代码:

After that, open the build.gradle of the module app and add the following code:

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'

    // Zxing libraries
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
    compile 'com.google.zxing:core:3.0.1'

}

最后,你需要从你的项目中删除google.zxing.integration.android,否则编译时会出现错误.

And finally, you need to delete google.zxing.integration.android from your project, otherwise, an error will show up when you compile.

更新:

要解决返回按钮问题,可以执行以下代码:

To resolve the back button problem, you can do the following code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {

        String _code = data.getStringExtra("SCAN_RESULT");

        // do whatever you want

    }

}

这篇关于如何将ZXING导入android studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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