Search code examples
androidandroid-studiobarcode-scanner

Scandit not working in Android Studio (only works in Eclipse)


I'm trying to get Scandit working in Android Studio - I have it working with eclipse, but when I try it in android studio I get an UnsatisfiedLinkError.

The version I am using is the scandit SDK community android 3.5.2. With android studio 0.3.7 and android 4.4 kitkat.

I tried it in android studio (latest version) following the same steps that I use for my eclipse test case, but my app crashes. The logcat shows:

java.lang.UnsatisfiedLinkError: Couldn't load scanditsdk-android-3.5.2 from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.zipier.qr_scanner_scandit-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.zipier.qr_scanner_scandit-1, /vendor/lib, /system/lib]]]: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:358)
        at java.lang.System.loadLibrary(System.java:526)
        at com.mirasense.scanditsdk.ScanditSDKBarcodePicker.initializeRecognitionEngine(ScanditSDKBarcodePicker.java:1298)
        at com.mirasense.scanditsdk.ScanditSDKBarcodePicker.<init>(ScanditSDKBarcodePicker.java:330)
        at com.mirasense.scanditsdk.ScanditSDKAutoAdjustingBarcodePicker.<init>(ScanditSDKAutoAdjustingBarcodePicker.java:59)
        at com.zipier.qr_scanner_scandit.MainActivity.initializeAndStartBarcodeScanning(MainActivity.java:41)
        at com.zipier.qr_scanner_scandit.MainActivity.onCreate(MainActivity.java:21)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

This is my source code:

public class MainActivity extends Activity implements ScanditSDKListener {
    private ScanditSDK mBarcodePicker;
    public static final String sScanditSdkAppKey = "pQqIxjG4EeOA8nxhinmFTJUHoJZP168Vn1rCM65paHw";

    static {
        System.loadLibrary("libscanditsdk-android-3.5.2");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initializeAndStartBarcodeScanning();
    }

    @Override
    protected void onPause() {
        mBarcodePicker.stopScanning();
        super.onPause();
    }

    @Override
    protected void onResume() {
        mBarcodePicker.startScanning();
        super.onResume();
    }


    public void initializeAndStartBarcodeScanning() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        ScanditSDKAutoAdjustingBarcodePicker picker = new ScanditSDKAutoAdjustingBarcodePicker(this, sScanditSdkAppKey, ScanditSDKAutoAdjustingBarcodePicker.CAMERA_FACING_FRONT);

        setContentView(picker);
        mBarcodePicker = picker;

        mBarcodePicker.getOverlayView().addListener(this);
    }

    public void didScanBarcode(String barcode, String symbology) {
        String cleanedBarcode = "";
        for (int i = 0; i < barcode.length(); i++) {
            if (barcode.charAt(i) > 30) {
                cleanedBarcode += barcode.charAt(i);
            }
        }

        if (symbology.equals("QR")) {
            Toast.makeText(this, cleanedBarcode, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void didCancel() {
        mBarcodePicker.stopScanning();
        finish();
    }

    @Override
    public void onBackPressed() {
        mBarcodePicker.stopScanning();
        finish();
    }

    @Override
    public void didManualSearch(String arg0) {
        // TODO Auto-generated method stub

    }
}

Solution

  • It's working now. Moritz on the Scandit team was a great help. He sent me this link: https://stackoverflow.com/a/17730219.

    Here's the fix:

    1. put the .so inside a lib/armeabi folder structure (lib not libs)
    2. zip it up
    3. add it to the libs folder of the project
    4. change the build.gradle file to compile it

    In my tests, Scandit works much better and faster than other qr code readers like zxing.