AM031447 AM031447 - 2 months ago 57
Android Question

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

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? To achieve QRCode scan

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'

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

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




4/10

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

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();
}


my 'build.greadle'

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

Answer

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.

EDIT:

Open up this file in your project:

/gradle/wrapper/gradle-wrapper.properties

Edit the distributionUrl line and set it too:

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

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

NEW EDIT:

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/"
    }

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

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'

}

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

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

    }

}
Comments