How to decode qrcode in Android mode ?

edited April 2017 in Android Mode

Hello, I'm trying to create a qrcode scanner for Android but it doesn't work. I've tried with 2 different librairies, com.cage.zxing4p3 (zxing4p3) and qrcodeprocessing. Here are the issues when I'm trying to decode it :

With zxing4p3 :

FATAL EXCEPTION: Animation Thread
Process: processing.test.lycee_loth, PID: 18058
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/image/BufferedImage;
    at com.cage.zxing4p3.ZXING4P.decodeImage(ZXING4P.java:123)
    at processing.test.lycee_loth.Lycee_Loth.mouseReleased(Lycee_Loth.java:441)
    at processing.core.PApplet.mouseReleased(Unknown Source)
    at processing.core.PApplet.handleMouseEvent(Unknown Source)
    at processing.core.PApplet.dequeueEvents(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.image.BufferedImage" on path: DexPathList[[zip file "/data/app/processing.test.lycee_loth-2/base.apk"],nativeLibraryDirectories=[/data/app/processing.test.lycee_loth-2/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 9 more

With qrcodeprocessing :

FATAL EXCEPTION: Thread-2
Process: processing.test.lycee_loth, PID: 22435
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/image/BufferedImage;
    at qrcodeprocessing.Decoder.scanImage(Decoder.java:113)
    at qrcodeprocessing.Decoder.run(Decoder.java:70)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.image.BufferedImage" on path: DexPathList[[zip file "/data/app/processing.test.lycee_loth-1/base.apk"],nativeLibraryDirectories=[/data/app/processing.test.lycee_loth-1/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 2 more

In my application, when I touch the screen :

if (qr_code == true) { // When the QR code menu is on
    //camera.savePhoto("qr_code_a_decoder.jpg");
    //photos.add(loadImage("/storage/emulated/0/Pictures/savedFrames/qr_code_a_decoder.jpg"));
    PImage code = createImage(camera.width, camera.height, RGB);
    code.copy(camera, 0, 0, camera.width, camera.height, 0, 0, camera.width, camera.height);
    code.updatePixels();
    //messageDecode = zxing4p.decodeImage(true, loadImage("qr_test.jpg"));
    //println(messageDecode);
    decoder.decodeImage(code);
  }

Is anybody has an idea ? :) Thanks.

Answers

  • those first two are the same problem:

    Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.image.BufferedImage" on path: DexPathList[[zip file "/data/app/processing.test.lycee_loth-2/base.apk"],nativeLibraryDirectories=[/data/app/processing.test.lycee_loth-2/lib/arm64, /system/lib64, /vendor/lib64]]

    i don't think the java.awt buffered images are available for android. which would mean you can't use zxing or qrcode. perhaps there are android equivalents?

    there is a specific android version of zxing - https://github.com/zxing/zxing - which might help. i guess you are using the processing library version...

  • Ok, I understand, I was just asking myself if these libraries could work with android mode. I will try the new library that you notified me, I'll tell you if it solved my issue ;) Thank you :)

  • But now, there is one more question, how to install it ? I'm sorry, but the only one library that I installed is readBox and I putted it in processing-3.3\modes\java\libraries but with this one it isn't working. Is it because it is not a java library for processing ? I don't find anything about how to install android libraries ...

  • @Felix56===

    you dont need any lib for doing that; just use the android API //developers.google.com/android/reference/com/google/android/gms/vision/barcode/BarcodeDetector

    and make some imports

    import com.google.android.gms.vision.CameraSource;
    import com.google.android.gms.vision.Detector;
    import com.google.android.gms.vision.Frame;
    import com.google.android.gms.vision.barcode.Barcode;
    import com.google.android.gms.vision.barcode.BarcodeDetector;
    
  • ... and I putted it in "processing-3.3\modes\java\libraries" ...

    That belongs to the installation path. We shouldn't modify any of those folders unless we know what we're doing! [-X

    Use your sketchbook folder path instead. Hit CTRL + COMMA in order to config it. :-B

  • Hi @akenaton, How can I use it with processing ? I tried to import them but they are not recognised by processing. I never created android applications except with MIT AppInventor 2. So I'm very interested about your solution. Thank you for your comment @GoToLoop.

  • @Felix56===

    sorry; i have too much things to do and i' ll post ASAP;

    yet= have you read the google docs for that??? - Have you add (meta-tags) GSM;vision asdependencies??? - Anyway i cannot see why it could not work with processing, and i am sure that it works because i have written app for that (with eclipse).

  • OK, I'll take more time this weekend to work on it and I will let you know about my progress. Thank you for your precious help. :)

  • Hello, I don't find anything about how to use these libraries with android mode for processing. I also find an other library for processing, but I think that I can't use it with the android mode. Here is the link (it is an old library) : thomasdiewald.com/blog/?p=855 I tried to integrate it in my application, but during the "building", I have this error :

    -dex:
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\bin\classes
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxingcore.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing_core.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\diewald_barcode.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing4p3.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\android-support-v4.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\ketai.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\qrcodeprocessing.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing_javase.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxingjavase.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\processing-core.jar
    input: C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\qrcode.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxingcore.jar -> zxingcore-8033d51243f18547f08f9cc2b4e7c633.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing_core.jar -> zxing_core-3a016e6f60329121fb2626f7650d30f3.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\diewald_barcode.jar -> diewald_barcode-a9c9f37af80b616d9dfd049382c680ab.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing4p3.jar -> zxing4p3-daf9fe2eee7c8d3a29edf1b3c3d90b0a.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\android-support-v4.jar -> android-support-v4-84bfd6a96b1e3a4a9404c49de52efdf5.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\ketai.jar -> ketai-6db99f1c34ded9c407682c160afb7be9.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\qrcodeprocessing.jar -> qrcodeprocessing-32a4603d605a544da043118c7ab0239f.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxing_javase.jar -> zxing_javase-50431ec39c2fa244db66b1b7075cab4e.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\zxingjavase.jar -> zxingjavase-c992af8b99260cf41cf0e63e89f50959.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\processing-core.jar -> processing-core-aa982846d8557659df55121c367482bc.jar
    Pre-Dexing C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\libs\qrcode.jar -> qrcode-013405d77b3aa4c5d73907067d67a9f8.jar
    Converting compiled files and external libraries into C:\Users\FLIX~1\AppData\Local\Temp\android6393965152887583450sketch\bin\classes.dex...
           [dx] 
           [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
           [dx] com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;
           [dx]     at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:591)
           [dx]     at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:546)
           [dx]     at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:528)
           [dx]     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
           [dx]     at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
           [dx]     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
           [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
           [dx]     at com.android.dx.command.dexer.Main.run(Main.java:277)
           [dx]     at com.android.dx.command.dexer.Main.main(Main.java:245)
           [dx]     at com.android.dx.command.Main.main(Main.java:106)
           [dx] 
    
    BUILD FAILED
    C:\Processing\modes\AndroidMode\sdk\tools\ant\build.xml:888: The following error occurred while executing this line:
    C:\Processing\modes\AndroidMode\sdk\tools\ant\build.xml:890: The following error occurred while executing this line:
    C:\Processing\modes\AndroidMode\sdk\tools\ant\build.xml:902: The following error occurred while executing this line:
    C:\Processing\modes\AndroidMode\sdk\tools\ant\build.xml:283: null returned: 2
    
    Total time: 34 seconds
    

    I'm waiting for your next answer, thank you for all. :)

  • edited May 2017

    I fixed this problem, now I can run my application with the diewald's library. The problem was that I was using zxing library at the same time. But the diewald's library is based on zxing, so there were some issues using these two at the same time. But now, when I try to decode a qrcode with this new library, I have the following issue :

    FATAL EXCEPTION: Animation Thread
    Process: processing.test.lycee_loth, PID: 7784
    java.lang.NoSuchMethodError: No virtual method getImage()Ljava/awt/Image; in class Lprocessing/core/PImage; or its super classes (declaration of 'processing.core.PImage' appears in /data/app/processing.test.lycee_loth-1/base.apk)
        at diewald_bardcode.Barcode.getBinaryBitmap(Unknown Source)
        at diewald_bardcode.Barcode.decode(Unknown Source)
        at processing.test.lycee_loth.Lycee_Loth.mouseReleased(Lycee_Loth.java:496)
        at processing.core.PApplet.mouseReleased(Unknown Source)
        at processing.core.PApplet.handleMouseEvent(Unknown Source)
        at processing.core.PApplet.dequeueEvents(Unknown Source)
        at processing.core.PApplet.handleDraw(Unknown Source)
        at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
        at processing.core.PApplet.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:761)
    

    It seems to be the same type of issue than the others that I already posted

    Thank you, still wainting for help ... :)

  • @Felix56=== java awt image cannot be used with android which has its own graphics package, hence the error: no workaround.

  • Ok, I understand. So we can conclude that we can't use the libraries that I found. But you talked about another solution which use BarcodeDetector with the Android API :

    you dont need any lib for doing that; just use the android API //developers.google.com/android/reference/com/google/android/gms/vision/barcode/BarcodeDetector

    So do you know how I could integrate it in my Processing code ? I also tried to convert the image with this import : import android.graphics;

    (from here : https://developer.android.com/reference/android/graphics/package-summary.html) But I don't understand how it works and what it's doing ... Thank you.

  • Hey Felix56, I remember dealing with a similar issue a while back. Unfortunately, I do't remember how I solved it in the end but I do remember it took some fiddling about to resolve.

  • Hey @Abbie6 thank you for your comment but do you remember if you used librairies for this ? Or had you to change the file format of the file to decode ? Do you remember when you did it ? What was the result ? It's been a long time that I'm looking for a solution to fix this problem. I hope that it will finally works because I need to finish it as quick as possible... Still looking for other solutions ...

Sign In or Register to comment.