简体   繁体   English

如何将ZXING导入android studio?

[英]How to import ZXING to android studio?

I use android studio I want to import 'ZXING' in my application, I find many articles and found the following site 我使用android studio我想在我的应用程序中导入'ZXING',我发现很多文章并找到了以下网站

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

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? 我下载了ZIP并解压缩,并找到了一些教程但是它似乎没有太详细的细节,我需要导入什么? To achieve QRCode scan 实现QRCode扫描

I still have no idea how to do it 我仍然不知道该怎么做


4/14 I tried Lennon URL provided "zxing-android-minimal" And import the 'gradle-wrapper.jar' 4/14我尝试了Lennon URL提供的“zxing-android-minimal”并导入'gradle-wrapper.jar'

But when I wrote new IntentIntegrator (this) .initiateScan (); 但是当我写了新的IntentIntegrator(this).initiateScan(); Still appear "Can not resolve symbol 'IntentIntegrator" message 仍然出现“无法解析符号'IntentIntegrator”消息

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 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

I do have a right '.jar select Add As Library But when an error occurs, he does not seem to be added 我有一个正确的'.jar选择添加为库但是当发生错误时,他似乎没有被添加


4/10 4/10

Finally no longer appear "Can not resolve symbol 'IntentIntegrator" this is the code,What do I wrong? 终于不再出现“无法解析符号'IntentIntegrator”这是代码,我有什么不对?

I removed the new IntentIntegrator (this) .initiateScan (); 我删除了新的IntentIntegrator(this).initiateScan(); 'applications normal operation '应用程序正常运行

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

my 'build.greadle' 我的'build.greadle'

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

I had many troubles when I developed my app using zxing library. 当我使用zxing库开发我的应用程序时,我遇到了很多麻烦。 So take a look this zxing minimal: https://github.com/Promptus/zxing-android-minimal/tree/master 所以看看这个zxing minimal: https//github.com/Promptus/zxing-android-minimal/tree/master

It worked perfectly to me and was easier to implement. 它对我来说很完美,并且更容易实现。

EDIT: 编辑:

Open up this file in your project: 在项目中打开此文件:

/gradle/wrapper/gradle-wrapper.properties /gradle/wrapper/gradle-wrapper.properties

Edit the distributionUrl line and set it too: 编辑distributionUrl行并设置它:

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

Update: You might want to use gradle-2.1-all.zip now. 更新:您现在可能想要使用gradle-2.1-all.zip。

NEW EDIT: 新编辑:

First of all, you must remove your libs file. 首先,您必须删除libs文件。 Then you have to remove 然后你必须删除

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

from your build.gradle of MyApplication , because that gradle is for the whole project, and it's better you use it in each module. 来自MyApplicationbuild.gradle ,因为该gradle适用于整个项目,并且最好在每个模块中使用它。

After that, open the build.gradle of the module app and add the following code: 之后,打开模块appbuild.gradle并添加以下代码:

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'

}

And finally, you need to delete google.zxing.integration.android from your project, otherwise, an error will show up when you compile. 最后,您需要从项目中删除google.zxing.integration.android ,否则,编译时会出现错误。

UPDATE: 更新:

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

    }

}

You should define your zxing dependency in build.gradle file: 您应该在build.gradle文件中定义zxing依赖项:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.zxing:core:3.2.0'
}

This is the Core barcode encoding/decoding library which you can use to build your custom barcode scanner/generator app. 这是Core条形码编码/解码库,您可以使用它来构建自定义条形码扫描器/生成器应用程序。

If you need to support just a simple case of scanning the barcode you can embed ZXing Android Barcode Scanner application using ZXing Android Embedded project. 如果您只需支持扫描条形码的简单案例,您可以使用ZXing Android Embedded项目嵌入ZXing Android Barcode Scanner应用程序。

This is a port of the ZXing Android Barcode Scanner application as an Android library project, for embedding in other Android applications. 这是ZXing Android Barcode Scanner应用程序的一个端口,作为Android库项目,用于嵌入其他Android应用程序。

If you decide to use the ZXing Android Embedded project it's as easy as defining your dependencies in build.gradle file: 如果您决定使用ZXing Android Embedded项目,那么就像在build.gradle文件中定义依赖项一样简单:

repositories {
    mavenCentral()

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

dependencies {
    implementation 'com.journeyapps:zxing-android-embedded:2.3.0@aar'
    implementation 'com.journeyapps:zxing-android-legacy:2.3.0@aar'
    implementation 'com.journeyapps:zxing-android-integration:2.3.0@aar'
    implementation 'com.google.zxing:core:3.2.0'
}

Launch the intent with the default options: 使用默认选项启动intent:

new IntentIntegrator(this).initiateScan(); // `this` is the current Activity

And get your result: 得到你的结果:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) {
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            // Parsing bar code reader result
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        }
        break;
    }
}

In your root-build.gradle: 在你的root-build.gradle中:

repositories {
   mavenCentral()

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

An in your app-build.gradle: 在你的app-build.gradle中:

dependencies {
    // Supports Android 4.0.3 and later (API level 15)
    compile 'com.journeyapps:zxing-android-embedded:2.3.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.journeyapps:zxing-android-legacy:2.3.0@aar'

    // Convenience library to launch the scanning 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.3.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.2.0'
}

More information could be found here: https://github.com/journeyapps/zxing-android-embedded 更多信息可以在这里找到: https//github.com/journeyapps/zxing-android-embedded

I was also encountered with same issue and I resolved it by following the simple steps as shown below: 我也遇到了同样的问题,我按照下面的简单步骤解决了这个问题:

Import the project android from downloaded zxing-master zip file using option Import project (Eclipse ADT, Gradle, etc.) and add the dollowing 2 lines of codes in your app level build.gradle file and and you are ready to run. 使用选项Import project (Eclipse ADT, Gradle, etc.)从下载的zxing-master zip文件导入项目android Import project (Eclipse ADT, Gradle, etc.)并在应用程序级build.gradle文件中添加2行代码,然后就可以运行了。

So simple, yahh... 这么简单,是啊......

dependencies {
        // https://mvnrepository.com/artifact/com.google.zxing/core
        compile group: 'com.google.zxing', name: 'core', version: '3.2.1'
        // https://mvnrepository.com/artifact/com.google.zxing/android-core
        compile group: 'com.google.zxing', name: 'android-core', version: '3.2.0'

    }

You can always find latest version core and android core from below links: 你总是可以从下面的链接找到最新版本的coreandroid core

https://mvnrepository.com/artifact/com.google.zxing/core/3.2.1 https://mvnrepository.com/artifact/com.google.zxing/android-core/3.2.0 https://mvnrepository.com/artifact/com.google.zxing/core/3.2.1 https://mvnrepository.com/artifact/com.google.zxing/android-core/3.2.0

After all the steps explained by Lennon, i resolve the problem of "Can not resolve symbol 'IntentIntegrator'" by going to the terminal on Android Studio and typed gradlew assemble. 在列侬解释完所有步骤之后,我通过转到Android Studio上的终端并键入gradlew汇编来解决“无法解析符号'IntentIntegrator'”的问题。 It took for a while but now i can use all of the classes declared on the aar. 花了一段时间,但现在我可以使用aar上声明的所有类。

Hope it helped. 希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM