15

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/"
    }
}
AM031447
  • 475
  • 1
  • 8
  • 21
  • You are not meant to "import" anything into your project. Use the core library via Maven. Do not copy `android` into your project. You're having trouble since this is not how you are intended to use it. – Sean Owen Apr 14 '15 at 11:08
  • You mean, I do not actually need to import any files into my project? – AM031447 Apr 14 '15 at 11:17

5 Answers5

13

You should define your zxing dependency in build.gradle file:

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.

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.

This is a port of the ZXing Android Barcode Scanner application as an Android library project, for embedding in other Android applications.

If you decide to use the ZXing Android Embedded project it's as easy as defining your dependencies in build.gradle file:

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:

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;
    }
}
Mr. Nobody
  • 119
  • 1
  • 2
  • 12
krebernisak
  • 950
  • 7
  • 16
9

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

    }

}
Lennon Spirlandelli
  • 3,131
  • 5
  • 26
  • 51
  • Thank u I'm still trying I imported gradle-wrapper.jar I according to the instructions, but still appears Can not resolve symbol 'IntentIntegrator' (Already added in build.gradle) – AM031447 Apr 09 '15 at 09:34
  • Did you added the `maven` repositorie? Such as : `repositories { mavenCentral() maven { url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/" } }` – Lennon Spirlandelli Apr 09 '15 at 12:53
  • Yes, I have to add the phrase And, there have been other mistakes when adding content dependencies {}, I will take a picture of the update in the article – AM031447 Apr 09 '15 at 17:29
  • You are using a gradle-wrapper.jar version that doesn't contain the command `compile()`. So you must use a new version instead. By the way, you don't need to put `compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'` and I also think you don't need to use gradle-wrapper.jar, cause you already have gradle installed. – Lennon Spirlandelli Apr 09 '15 at 18:34
  • is wrapper folder where gradle-wrapper.jar old it? where can i find new version? – AM031447 Apr 10 '15 at 12:53
  • When you create a new project at Android Studio, it has the gradle already installed – Lennon Spirlandelli Apr 10 '15 at 13:04
  • How do I solve this problem? I mean, "Can not resolve symbol 'IntentIntegrator" – AM031447 Apr 11 '15 at 17:24
  • That error means you didn't install the zxing library correctly. And you'll only manager to install after updating your gradle. If I were you I tried to create a new project in the Android Studio and tried to install again the zxing library I sent to you – Lennon Spirlandelli Apr 11 '15 at 17:44
  • Thank you, I keep try But always an error ,I guess I do not know how to properly install zxing library ,Still thank you for helping me – AM031447 Apr 13 '15 at 06:56
  • Thank you, 'Can not resolve symbol' IntentIntegrator issue is resolved But I ran '' new IntentIntegrator (this) .initiateScan (); "he still stopped – AM031447 Apr 14 '15 at 11:07
  • Try to trigger that code in a button and be careful with `this` in the button. Change it to `NameOfActivity.this`. Otherwise, you can send me your project to me, so I could take a look – Lennon Spirlandelli Apr 14 '15 at 12:50
  • I try, but still, this is the project https://www.dropbox.com/s/ureu72rankiedks/MyApplication.zip?dl=0 – AM031447 Apr 15 '15 at 07:35
  • I fixed the problem. You've had the same problem I'd had when I tried to use zxing as a library and `Integrator` as a class in my project. Anyway, there are some steps you have to do, so I edited my answer. – Lennon Spirlandelli Apr 15 '15 at 13:55
  • Success! He began scanning! Thank you very much :D – AM031447 Apr 16 '15 at 10:45
  • Great! Now you just have to code the return from scan – Lennon Spirlandelli Apr 16 '15 at 12:02
  • I found that if I press the Back button without capture, app will close there any solution? – AM031447 Apr 24 '15 at 12:54
  • @Lennon: Excuse me, bro. With ZXing-Android-Minimal, is it possible to add Zxing scanner into a custom layout on activity? Thank you very much! – Neo Sep 17 '15 at 07:52
  • @MrNeo Yeah, for sure. You can create a custom layout for the scanner and set 'integrator.setCaptureLayout(R.layout.custom_layout)' before call 'initiateScan();' – Lennon Spirlandelli Sep 17 '15 at 12:32
  • @Lennon: Sorry for the inconvenient, could you please help me with this question: http://stackoverflow.com/questions/32627145/zxing-barcode-scanner-in-custom-layout-in-fragment! – Neo Sep 18 '15 at 01:23
  • @MrNeo Of curse buddy. I'll try though. – Lennon Spirlandelli Sep 18 '15 at 12:59
5

In your root-build.gradle:

repositories {
   mavenCentral()

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

An in your 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

Christopher
  • 9,682
  • 7
  • 47
  • 76
3

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.

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:

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

Smeet
  • 4,036
  • 1
  • 36
  • 47
1

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. It took for a while but now i can use all of the classes declared on the aar.

Hope it helped.