[2.0.6]sikulixapi usage in Gradle projects

Asked by Juliana XIAO

I have 7 maxOS test machines, 6 of them are macOS Big Sur and they all working well with sikulixapi 2.0.4 OCR feature. But 1 machine is macOS Monterey which uses Apple M1 Chip and all the libraries are under different location. I can find "/usr/local/opt/leptonica/lib/liblept.5.dylib" on the other 6 test machines, but on this machine I find it is located under "/opt/homebrew/Cellar/leptonica/1.82.0/lib/liblept.5.dylib". Basically, I found all the brew installed libraries under "/usr/local/Cellar" on those 6 machines are under "/opt/homebrew/Cellar" on this one special machine. So that when I run test on that special machine from eclipse it gives me the following error:
************************************************************************
org.sikuli.script.SikuliXception: OCR: start: Tesseract library problems: dlopen(/Users/rr_admin/Library/Caches/JNA/temp/jna12082671447273670762.tmp, 0x0009): Library not loaded: /usr/local/opt/leptonica/lib/liblept.5.dylib
  Referenced from: /Users/rr_admin/Library/Caches/JNA/temp/jna12082671447273670762.tmp
  Reason: tried: '/usr/local/opt/leptonica/lib/liblept.5.dylib' (no such file), '/usr/lib/liblept.5.dylib' (no such file)
 at org.sikuli.script.TextRecognizer.getTesseractAPI(TextRecognizer.java:111)
 at org.sikuli.script.TextRecognizer.doRead(TextRecognizer.java:350)
 at org.sikuli.script.TextRecognizer.readText(TextRecognizer.java:309)
 at org.sikuli.script.OCR.readText(OCR.java:691)
 at org.sikuli.script.OCR.readText(OCR.java:679)
 at org.sikuli.script.Element.text(Element.java:147)
 at com.pyrsoftware.av.client.desktop.mac.SikuliScreen.grabTextOnRight(SikuliScreen.java:203)
 at com.pyrsoftware.av.client.desktop.helpers.SikulixHelper.parseVersion(SikulixHelper.java:106)
**************************************************************************
Is there any workaround for this?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
RaiMan (raimund-hocke) said (last edit ):
#1

You have to understand the Homebrew concept for macOS M1 machines (see Home-brew docs).

In 2.0.6 (only snapshots available at the moment) I try to reflect all specific aspects of macOS M1 with respect to SikuliX

The snippets from 2.0.6 are only to give you some insights about what you would have to do in your wrapper.
Setting the jna-path correctly is the key feature.

     if (Commons.runningMac()) {
        String libPath = "/usr/local/lib";
        if (Commons.runningMacM1()) {
          libPath = "/opt/homebrew/lib";
        }
        File libTess = new File(libPath, "libtesseract.dylib");
        if (libTess.exists()) {
          Commons.jnaPathAdd(libPath); //----------------------------- add the path
        } else {
          throw new SikuliXception(String.format("OCR: validate: libtesseract.dylib not in %s", libPath));
        }
      }

// the respective method from Commons:

  public static String jnaPathAdd(String sFolder) {
    String jnaPath = System.getProperty("jna.library.path");
    if (null == jnaPath) {
      jnaPath = "";
    }
    File folder = new File(sFolder);
    if (!folder.exists()) {
      return null;
    }
    if (!jnaPath.isEmpty()) {
      jnaPath = File.pathSeparator + jnaPath;
    }
    jnaPath = folder.getAbsolutePath() + jnaPath;
    System.setProperty("jna.library.path", jnaPath);
    return jnaPath;
  }

Revision history for this message
Juliana XIAO (juliana-x) said :
#2

Hi! Raiman,

Thanks for this quick reply. What I understand is that I'd better wait for 2.0.6 in order to use this machine, right?

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

It would be helpful if you try with the actual snapshot 2.0.6 from today.

Waiting for the final release does not change your situation:
On macOS M1 you will always need a valid Homebrew setup or a symlink for libtesseract.dylib in a folder /opt/homebrew/lib.

The actual snapshot and hence the final version needs Tesseract 5.0.1

Revision history for this message
Juliana XIAO (juliana-x) said :
#4

Hi! RaiMan,

Could you please let me know where to download actual snapshot 2.0.6 and how to use it?

Thanks,
Juliana

Revision history for this message
RaiMan (raimund-hocke) said :
#5
Revision history for this message
Juliana XIAO (juliana-x) said :
#6
Revision history for this message
Juliana XIAO (juliana-x) said :
#7

Hi! RaiMan,

I found the 2.0.6 jar file but it is sikulixide jar file. Where can I find sikulixapi jar file so that I can run my test case written in java from eclipse?

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

Maven coordinates:
com.sikulix::sikulixapi::2.0.6-SNAPSHOT
from
snapshot-repo OSSRH

Revision history for this message
Juliana XIAO (juliana-x) said :
#9

Hi! RaiMan,

I have a Gradle java project and in build.gradle file I put the following line
api "com.sikulix.sikulixapi:2.0.6-SNAPSHOT:2.0.6"
I got the following issue:
Could not resolve: com.sikulix.sikulixapi:2.0.6-SNAPSHOT:2.0.6

If I put
api "com.sikulix:sikulixapi:2.0.6-SNAPSHOT"
I got following issue:
Could not resolve: com.sikulix:sikulixapi:2.0.6-SNAPSHOT

I don't know how to make it work in my Gradle java project. Could you please help?

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

Sorry, no Gradle experience.

Correct should be:
com.sikulix:sikulixapi:2.0.6-SNAPSHOT

But I guess (as with Maven) you have to tell Gradle about the snapshot repository on OSSRH:

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

This is for Maven, but there surely is a similar option with Gradle.

Revision history for this message
Juliana XIAO (juliana-x) said :
#11

Hi! RaiMan,

I just tried this yesterday and made it work with following build.gradle configuration. Both options are working fine: Sikuli can find images and do the click.
Option1:
*************************************
repositories {
 maven {
  url = 'https://oss.sonatype.org/content/repositories/snapshots'
 }
}
dependencies {
 api(group: 'com.sikulix', name: 'sikulixapi', version: '2.0.6-SNAPSHOT')
}
*************************************

Option2:
*************************************
repositories {
 maven {
  url = 'https://oss.sonatype.org/content/repositories/snapshots'
 }
}
dependencies {
 compile "com.sikulix:sikulixapi:2.0.6-SNAPSHOT"
}
*************************************

But I encountered a new issue: when I tried to recognize text from an image using the following code:
screen.find(new Pattern(imageFileName).similar((float) similarity).targetOffset(image.getOffsetX(),
          image.getOffsetY())).right(offset).text().trim()
I got the following error:
*************************************
org.sikuli.script.SikuliXception: OCR: validate: libtesseract.dylib not in /usr/local/lib
 at org.sikuli.script.TextRecognizer.get(TextRecognizer.java:87)
 at org.sikuli.script.OCR.readText(OCR.java:722)
 at org.sikuli.script.OCR.readText(OCR.java:707)
 at org.sikuli.script.Element.text(Element.java:1155)
*************************************
I found the actual location is "/opt/homebrew/Cellar/tesseract/5.0.1/lib/libtesseract.dylib". Could you please help?

Thanks,
Juliana

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

--- I found the actual location is "/opt/homebrew/Cellar/tesseract/5.0.1/lib/libtesseract.dylib".
This is we're the stuff is built and made ready.
finally there are symlinks created in /opt/homebrew/lib (brew link ...). there should be a libtesseract.dylib as symlink.
See comment #1.

Revision history for this message
Juliana XIAO (juliana-x) said :
#14

Hi! RaiMan,

I changed some configuration in gradle.build and installed some libraries on M1 CPU mac machine. Now I still can do the click and verify image with sikuli2.0.6-SNAPSHOT but I still cannot get text from image and I see the following error which is different than above. Do you have any idea that why I get the following error?
***********************************************************************
org.sikuli.script.SikuliXception: OCR: start: Tesseract library problems: Error looking up function 'TessBaseAPIInitLangMod': dlsym(0x205632c00, TessBaseAPIInitLangMod): symbol not found
        at org.sikuli.script.TextRecognizer.getTesseractAPI(TextRecognizer.java:213)
        at org.sikuli.script.TextRecognizer.doRead(TextRecognizer.java:437)
        at org.sikuli.script.TextRecognizer.readText(TextRecognizer.java:414)
        at org.sikuli.script.OCR.readText(OCR.java:722)
        at org.sikuli.script.OCR.readText(OCR.java:707)
        at org.sikuli.script.Element.text(Element.java:1155)
***********************************************************************

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

Just checked again on my iMac M1.

My Tesseract is on version 5.0.3 and it works.

Put a
Debug.on(3);
before the first use of any SikuliX feature and you should get logs like this when using find() and text():

[debug] OCR: Tesseract version found: 5.3.0 expected: 5.0.1 --- should work
[debug] OCR: Tess4J 5.1.1 --- Tesseract 5.3.0
[debug] loadLibrary: trying: opencv_java454
[debug] libsFolder: has wrong content: /Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs
[debug] libsFolder: created /Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs (2.0.6-SNAPSHOT-202208171131)
[debug] libsExport: libopencv_java454.dylib
[debug] libsExport: keyboard
[debug] loadLibrary: success: /Users/raimundhocke/Library/Application Support/Sikulix/SikulixLibs/libopencv_java454.dylib

Revision history for this message
Anna Yanakieva (annayanakieva) said :
#16

Hi RaiMan, I am having issues with Sikulli on my M1 Mac as well. I have added the snapshots repo to my build.gradle file like this:

exclusiveContent {
  forRepository {

   maven {
    name = 'OSSRH-Snapshots'
    url = 'https://oss.sonatype.org/content/repositories/snapshots'
    mavenContent {
     snapshotsOnly()
    }
   }
  }
  filter {
   includeGroup 'com.sikulix'
  }
 }

api(group: 'com.sikulix', name: 'sikulixapi', version: '2.0.6-SNAPSHOT')

However, when I build the project, I am getting the following error:

  > Could not find org.openpnp:opencv:[4.7.0,].
     Searched in the following locations:
       - https://repo1.maven.org/maven2/org/openpnp/opencv/[4.7.0,]/opencv-[4.7.0,].pom
       - https://oss.sonatype.org/content/repositories/releases/org/openpnp/opencv/[4.7.0,]/opencv-[4.7.0,].pom
     Required by:
         project :TestNGFramework > com.sikulix:sikulixapi:2.0.6-SNAPSHOT:20230417.153849-20

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Do you have an idea what might be wrong? I can see that the version of opencv looks strange "opencv-[4.7.0,]"(there is a comma in the end, which might be causing the issue). If I try to browse the repository manually, I can find https://repo1.maven.org/maven2/org/openpnp/opencv/4.7.0-0/

Thank you in advance for your help!

Anna

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

@Anna
> Could not find org.openpnp:opencv:[4.7.0,].

sikulixapi pom has this dependency with a version [4.7.0,] which in Maven means: take at least version 4.7.0, but if available any newer version .

I have no Gradle experience and do not know how to tell Gradle, what to do with such a version specification.

May be it is possible to tell Gradle to ignore it and you might add a correct dependency for org.openpnp:opencv:4.7.0 or so.

Can you help with this problem?

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

To post a message you must log in.