java 如何将 Zxing 库包含到 android 项目中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17026904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include Zxing library to android project?
提问by Vannian
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.
我已经在 stackoverflow 中阅读了这个问题的一些答案,但它对我不起作用。我已经有一个项目,现在我想将二维码和条码阅读器集成到我的项目中。
I downloaded the zip file from: core-2.2.zip
我从以下位置下载了 zip 文件: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?
我没有找到任何“core.jar”,我读到我必须集成添加到“core”文件夹中的文件。我是否必须将所有类添加到我的项目(整个文件夹)中?还是我必须使用该文件夹创建一个 jar 文件?
I am using Android Studio. Any one can help me? thank you
我正在使用 Android Studio。任何人都可以帮助我吗?谢谢
回答by mhcuervo
There is indeed an Android application that is part of the ZXing project. It uses the coremodule 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.xmlfile:
确实有一个 Android 应用程序是 ZXing 项目的一部分。它使用maven central发布的核心模块。如果您有一个 maven 项目(这对于大多数 Android 应用程序来说不太可能),您可以将以下依赖项添加到您的pom.xml文件中:
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.2.0</version>
</dependency>
for a Gradleproject:
对于Gradle项目:
compile 'com.google.zxing:core:3.2.0'
or you can directly download the compiled .jar from here.
或者你可以直接从这里下载编译好的 .jar 。
Please, notice that this answer refers to version 3.2.0 which is the latest stable one. Version 2.2 could be similarly obtained.
请注意,这个答案是指最新的稳定版本 3.2.0。可以类似地获得2.2版。
回答by Jayakrishnan Salim
For QRCode reading you can also use Google Play service 7.8 and beyond. You may check this link from Google.
回答by NHTorres
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.
你应该做的是包含一个jar,你不能下载。起初当你尝试使用 zxing 时遇到了同样的问题,幸运的是我找到了 jar 并且可以下载它。您必须验证您需要的任一版本。
I have not worked in Android Studio, this is in eclipse but I imagine it must be the same way.
我没有在 Android Studio 中工作过,这是在 eclipse 中,但我想它必须是相同的方式。
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.
您需要添加的是完整的项目 zxing 作为主项目的库到您的项目中。Activity 并创建一个包含此库的布局。
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>