ADBScreen.capture(): UnsatisfiedLinkError with OpenCV Mat

Asked by Wendell

Hi,
I‘m trying to use ADBScreen to make autotest on android devices,I have read the source code and some questions about this
So there is the simple test code
import org.sikuli.android.ADBScreen as ADB
ab = ADB.start()
ab.aKey(3)
#ab.aTap(img)
ab.click(img)

the error log :
ADBScreen: Android device: 55CDU16C07013395 (1920 x 1080)
[error] script [ test1.2 ] stopped with error in line 5
[error] java.lang.UnsatisfiedLinkError ( java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J

The Sikulix version is 1.1.2, I tried to use a android simulator or a real device but both doesn't work.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
TestMechanic (ndinev) said :
#1

I do not see "img" defined

Revision history for this message
Wendell (wendellliu) said :
#2

@ dinev
img here is a path,I just use 'img' to replace a real image path for simplicity: )

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Looks like you did not run a correct setup, since such errors only happen in case of missing native library packages.

Revision history for this message
Wendell (wendellliu) said :
#4

Hi RaiMan ,I traced the problem with using java api and here is the debug info:
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J
 at org.opencv.core.Mat.n_Mat(Native Method)
 at org.opencv.core.Mat.<init>(Mat.java:481)
 at com.company.Main.main(Main.java:15)

something error happened with this code in org.opencv.core.Mat
n_Mat(rows, cols, type);

My system is Windows7 64x, and jdk version is 1.8.0 64x, Sikulix is 1.1.2.
I install Sikulix just doubleclick the jar file and following the setup steps. I don't know what's wrong here.

And I googled the same error https://github.com/atduskgreg/opencv-processing/issues/39
Maybe it's a bug from the version of opencv which was used in sikulix?
How can I solve with this problem?
Thank you RaiMan : )

Revision history for this message
RaiMan (raimund-hocke) said :
#5

ok, understood.

You are using the OpenCV Java API directly from your code.
I am sorry, but I cannot support these kind of problems, because they have nothing to do with SikuliX.

The bundled prebuilt OpenCV Java API is for internal use only.
You may use it, but at your own risk.

Revision history for this message
Wendell (wendellliu) said :
#6

Hi RaiMan,
I'm trying to figure out this problem because I only want to use the method which afford by sikulix to interact with android devices.
Just like
import org.sikuli.android.ADBScreen as ADB
ab = ADB.start()
ab.aTap('img')

but the exception is :
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J

there is something wrong in ADBDevice.java , function captureDeviceScreenMat()
line 205 : Mat matOrg = new Mat(actH, actW, CvType.CV_8UC4);
So There was a mistake in calling the function Mat() from opencv

I had tested the aSwipe and aKey function run correctly but because of the error , captureScreen can not be used.

Then I try using Java and import sikulixapi.jar to test where is wrong.
I had read this question https://answers.launchpad.net/sikuli/+question/626490 ,
and write this code to test:
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);//without this line, the same error will be reported
        int actH = 1080;
        int actW = 720;
        Mat matOrg = new Mat(actH, actW, CvType.CV_32FC2);

run it, a new error will be reported :
Java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path

I searched the file in sikulixapi and the folder :C:\Users\Administrator\AppData\Roaming\Sikulix\SikulixLibs_201707260804
there are some files about opencv:
libopencv_core248.dll
libopencv_features2d248.dll
libopencv_flann248.dll
libopencv_highgui248.dll
libopencv_imgproc248.dll
libopencv_java248.dll

but no opencv_java248
Now I'm confused and don't know how to deal with it. I just only want to use the ADBDevice and ADBScreen but the key function
exists,find,aTap can't work.
Anyway thanks RaiMan, you helps me alot : )

Revision history for this message
RaiMan (raimund-hocke) said :
#7

ok, I will check latest within the next 24 hours.

Revision history for this message
RaiMan (raimund-hocke) said :
#8

I just tested on my Mac with a Nexus7/Android 6 attached.
Everything works as expected.

I will now have to check on Windows (only Win 10 64 available).

BTW: by convention: a library opencv_java248 will be looked for as libopencv_java248.dll (which indeed exists in the package).

what I did:
In the SikuliX IDE, I first made the checks from the Tools menu.
Then I made the Nexus the default screen (Tools menu) and captured an image (app icon) from the home screen and ran this script:

import org.sikuli.android.ADBScreen as ADB
dev = ADB.start()
img = "img.png"
dev.aTap(img)

which successfully opened the app.

Revision history for this message
Wendell (wendellliu) said :
#9

Hi RaiMan,
The result that i made the checks from the tools menu seems that go to the default screen and swipe left right run successfully, but when try to run a tap, the ide has no response, after a few seconds, i had to abort it and there are some error :
it seems that because of the same reason.

[error] ADBDevice: exec: getprop: se.vidstige.jadb.JadbException: command failed: device offline

[error] ADBDevice: dumpsys: display: se.vidstige.jadb.JadbException: command failed: device offline
[error] ADBDevice: getDisplayDimension: dumpsys display: token not found: mDefaultViewport= ... deviceWidth=1200, deviceHeight=1920}
[error] IDE: Problem when trying to invoke menu action android Error: null

[error] ADBDevice: isDisplayOn: (Android version -1) dumpsys power: pattern not found: mScreenOn=(..)
[error] ADBScreen: wakeUp: not possible - see log

Exception in thread "Thread-12" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.<init>(Mat.java:481)
at org.sikuli.android.ADBDevice.captureDeviceScreenMat(ADBDevice.java:207)
at org.sikuli.android.ADBDevice.captureDeviceScreen(ADBDevice.java:145)
at org.sikuli.android.ADBDevice.captureScreen(ADBDevice.java:136)
at org.sikuli.android.ADBScreen.capture(ADBScreen.java:152)
at org.sikuli.android.ADBScreen.capture(ADBScreen.java:144)
at org.sikuli.util.OverlayCapturePrompt.prompt(OverlayCapturePrompt.java:211)
at org.sikuli.android.ADBScreen$1.run(ADBScreen.java:207)

Exception in thread "Thread-11" java.lang.NullPointerException
at org.sikuli.android.ADBTest.ideTest(ADBTest.java:99)
at org.sikuli.ide.SikuliIDE.androidSupportTest(SikuliIDE.java:1794)
at org.sikuli.ide.SikuliIDE.access$2500(SikuliIDE.java:106)
at org.sikuli.ide.SikuliIDE$1.run(SikuliIDE.java:1778)

Revision history for this message
Wendell (wendellliu) said :
#10

Hi RaiMan,
Have you done a test on your win10 x64?
I do not have mac so couldn't test it.
But I think I had test it on 2 different machines and both 32bit and 64bit win7 with the same version of jdk,
Will there be some problems with the windows?
Looking forward to your reply. : )

Wendell

Revision history for this message
Madhusudhan (madhusudhan-jr) said :
#11

Hi RaiMan,

I am also facing the above issue. Am trying to run Sikuli on Android Emulator with API level 23. Getting below error!!
I have also installed SikuliX as per the expected way.

I tried the sikuli version, 1.1.1 and 1.1.2. Getting error in both the versions.
Please do assist.

Error:
" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J"

Sikuli Version:

               <repository>
   <id>sonatype-ossrh</id>
   <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  </repository>

                 <dependency>
   <groupId>com.sikulix</groupId>
   <artifactId>sikulixapi</artifactId>
   <version>1.1.2-SNAPSHOT</version>
  </dependency>

Revision history for this message
Madhusudhan (madhusudhan-jr) said :
#12

(Continued) My sikuli snippet:

ADBScreen adb = ADBScreen.start();
  adb.click("PathToImage");
  adb.stop();

Am using Windows XP.

Revision history for this message
RaiMan (raimund-hocke) said :
#13

Uuups, I totally lost contact to that problem.

Will try to check the next days.

Thanks for the reminder.

Revision history for this message
Madhusudhan (madhusudhan-jr) said :
#14

Hi RaiMan,

Thanks for the info!.
Also looking forward to C# integration with SikuliX 2.0!! Please update the info!

Revision history for this message
RaiMan (raimund-hocke) said :
#15

Where did you get the info, that 2.0 wil integrate with C#?
I do not have any plans in that direction.l

Revision history for this message
gautam (dpadhy) said :
#16

This problem is arising for me on MAC as well - Mac High Sierra 10.13.5

I have checked out the sikulix 1.1.3 branch.. Fixed an issue with jadb missing version and running the following test

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.sikuli.android.ADBClient;
import org.sikuli.android.ADBDevice;
import org.sikuli.script.ScreenImage;

import se.vidstige.jadb.JadbDevice;

public class ClickTest {

 @Test
 public void testClickAtLocation() {

  ADBClient client = new ADBClient() ;
  assertTrue ( ADBClient.isAdbAvailable) ;

  JadbDevice device = ADBClient.getDevice() ;
  assertTrue ( device != null) ;

  ADBDevice device1 = ADBDevice.init() ;
  assertTrue(device1 != null) ; // until here everything works fine and it retrieves the devices

  ScreenImage image = device1.captureScreen() ; // here it throws the UnsatisfiedLinkError.
  image.save("/Users/..../sikulix", "testImageCapture.png") ;
 }

}

Looking further. I am guessing its an issue with the setup of api.

Can you help with this problem?

Provide an answer of your own, or ask Wendell for more information if necessary.

To post a message you must log in.