如何将ZXING导入android studio? [英] How to import ZXING to 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
我确实有一个正确的 '.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/"
}
来自 MyApplication
的 build.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屋!