Skip to content

Commit

Permalink
Improve native load
Browse files Browse the repository at this point in the history
  • Loading branch information
Nain57 committed Nov 25, 2023
1 parent 7fc9f8b commit a223379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import androidx.annotation.Keep
* Debug flavour of the library is build against build artifacts of OpenCv in the debug folder.
* Release flavour of the library is build against the sources of the OpenCv project, downloaded from github.
*/
class NativeDetector : ImageDetector {
class NativeDetector private constructor() : ImageDetector {

companion object {
// Used to load the 'smartautoclicker' library on application startup.
init {
fun newInstance(): NativeDetector? = try {
System.loadLibrary("smartautoclicker")
NativeDetector()
} catch (ex: UnsatisfiedLinkError) {
null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ internal class DetectorEngine(context: Context) {
return
}

val detector = try {
NativeDetector()
} catch (ex: UnsatisfiedLinkError) {
val detector = NativeDetector.newInstance()
if (detector == null) {
Log.e(TAG, "startDetection: native library not found.")
_state.value = DetectorState.ERROR_NATIVE_DETECTOR_LIB_NOT_FOUND
return
Expand Down

0 comments on commit a223379

Please sign in to comment.