How to include Zxing library to android project?

2019-03-27 19:47发布

问题:

I have read some answer for this question in stackoverflow, but it is not working for me. I have already a project, and now I want to integrate QR Code and barcode reader into my project.

I downloaded the zip file from: core-2.2.zip

I didn't find any "core.jar", I read that I have to integrate files added in "core" folder. Do I have to add all classes to my project (the whole folder)? or do I have to create a jar file with that folder?

I am using Android Studio. Any one can help me? thank you

回答1:

There is indeed an Android application that is part of the ZXing project. It uses the core module released in maven central. If you have a maven project (which is unlikely for most Android applications) you can add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>3.2.0</version>
</dependency>

for a Gradle project:

compile 'com.google.zxing:core:3.2.0'

or you can directly download the compiled .jar from here.

Please, notice that this answer refers to version 3.2.0 which is the latest stable one. Version 2.2 could be similarly obtained.



回答2:

For QRCode reading you can also use Google Play service 7.8 and beyond. You may check this link from Google.



回答3:

What you should do is to include a jar, you can not be downloaded. At first when you try to take zxing had the same problem, luckily I found the jar and I could download it. You have to verify either version which you need.

core

I have not worked in Android Studio, this is in eclipse but I imagine it must be the same way.

What you need to add it is the full project zxing to your project as a library to the main project. Activity and create a layout that include this library.

Which is also the default is:

public class Validador extends CaptureActivity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.validador);
}

}

Layout :

<FrameLayout
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:layout_gravity="center">
    <include layout="@layout/capture"/>
</FrameLayout>