I'm using ScanLibrary from here. I've successfully implemented this and it is working fine on all devices (e.g. Moto X) except the Xiomi MI redmi 3S prime and MI 4i. I wonder why it isn't working on Xiomi. I've tested this on Marshmallow, Lollipop and other API's as well and it's working fine on all other devices, only the Xiomi have problems. I also tried to reported this on their Github page but got no reply so my last hope is Stack Overflow.
I'm getting following exception on Xiomi devices:
05-18 15:33:33.504 21553-21553/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.vikast.includelibrariesdemo, PID: 21553
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.vikast.includelibrariesdemo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.vikast.includelibrariesdemo-2/lib/arm64, /data/app/com.example.vikast.includelibrariesdemo-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libopencv_java3.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.scanlibrary.ScanActivity.<clinit>(ScanActivity.java:125)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
The library class where i'm getting error:
ScanActivity.java
package com.scanlibrary;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.ComponentCallbacks2;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
/**
* Created by jhansi on 28/03/15.
*/
public class ScanActivity extends Activity implements IScanner, ComponentCallbacks2 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan_layout);
init();
}
private void init() {
PickImageFragment fragment = new PickImageFragment();
Bundle bundle = new Bundle();
bundle.putInt(ScanConstants.OPEN_INTENT_PREFERENCE, getPreferenceContent());
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.commit();
}
protected int getPreferenceContent() {
return getIntent().getIntExtra(ScanConstants.OPEN_INTENT_PREFERENCE, 0);
}
@Override
public void onBitmapSelect(Uri uri) {
ScanFragment fragment = new ScanFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ScanConstants.SELECTED_BITMAP, uri);
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.addToBackStack(ScanFragment.class.toString());
fragmentTransaction.commit();
}
@Override
public void onScanFinish(Uri uri) {
ResultFragment fragment = new ResultFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ScanConstants.SCANNED_RESULT, uri);
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.addToBackStack(ResultFragment.class.toString());
fragmentTransaction.commit();
}
@Override
public void onTrimMemory(int level) {
switch (level) {
case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
/*
Release any UI objects that currently hold memory.
The user interface has moved to the background.
*/
break;
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
/*
Release any memory that your app doesn't need to run.
The device is running low on memory while the app is running.
The event raised indicates the severity of the memory-related event.
If the event is TRIM_MEMORY_RUNNING_CRITICAL, then the system will
begin killing background processes.
*/
break;
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
/*
Release as much memory as the process can.
The app is on the LRU list and the system is running low on memory.
The event raised indicates where the app sits within the LRU list.
If the event is TRIM_MEMORY_COMPLETE, the process will be one of
the first to be terminated.
*/
new AlertDialog.Builder(this)
.setTitle(R.string.low_memory)
.setMessage(R.string.low_memory_message)
.create()
.show();
break;
default:
/*
Release any non-critical data structures.
The app received an unrecognized memory level value
from the system. Treat this as a generic low-memory message.
*/
break;
}
}
public native Bitmap getScannedBitmap(Bitmap bitmap, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
public native Bitmap getGrayBitmap(Bitmap bitmap);
public native Bitmap getMagicColorBitmap(Bitmap bitmap);
public native Bitmap getBWBitmap(Bitmap bitmap);
public native float[] getPoints(Bitmap bitmap);
//========== GETTING ERROR OVER HERE ================//
static {
System.loadLibrary("opencv_java3"); //========== HERE IS THE ERROR ================//
System.loadLibrary("Scanner");
}
}
After some attempts I have found this solution
I had made some changes to gradle and now it's work fine
In app gradle.build add these lines in defaultConfig{}
defaultConfig{
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}
}
and some changes in gradle.properties
android.useDeprecatedNdk=true
Now it works for me. I think it will help someone also