QuickBirdEng / opencv-android

Easy way to integrate OpenCv into your Android project via Gradle
Other
684 stars 123 forks source link

Gradle sync failed and then fails to load #18

Closed goatchurchprime closed 4 years ago

goatchurchprime commented 5 years ago

The error I started with was here:

20:52   Gradle sync started with single-variant sync
20:52   Gradle sync failed: Plugin with id 'com.github.dcendents.android-maven' not found. (524 ms)
20:52   NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
20:53   Gradle sync started with single-variant sync
20:53   Gradle sync failed: Plugin with id 'com.github.dcendents.android-maven' not found. (457 ms)
20:53   NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
ERROR: Plugin with id 'com.github.dcendents.android-maven' not found.

It seemed like it had to do with the line in the file opencv4_1_0_contrib/build.gradle

apply plugin: 'com.github.dcendents.android-maven'
group = publishedGroupId                               // Maven Group ID for the artifact

The repository https://github.com/dcendents/android-maven-gradle-plugin (which might have something to do with this) says:

Abandoned

I've stopped doing android development yeard ago, and gradle making constant changes to their build system made supporting that plugin quite hard for me.

If you are using Kotlin 1.3.30+ and Gradle 5.x, please use https://github.com/sky-uk/gradle-maven-plugin instead.

Naively replacing the above with the line apply plugin: 'com.github.sky-uk.gradle-maven-plugin' didn't work.

Working from the other end from what works, I loaded this app project into the AndroidStudio, set its module dependency to be opencv4_1_0_contrib, changed the build.gradle (Module: app) android { defaultConfig { minSdkVersion from 19 to 21 (as suggested in the errors), noted that the project Gradle Version was 4.6, and it ran and installed and said "Hello World!".

Then I noticed a "Plugin Update Recommended" in AndroidStudio, that said:

To take advantage of the latest features, improvements, and security fixes, we strongly recommend that you update the Android Gradle plugin from the current version 3.1.2 to version 3.5.1 and Gradle to version 5.4.1.

So I clicked on update, and it stopped working. So I thought that the Gradle 5.4.1 is the problem. However, when I removed all the instances of android:minSdkVersion="8" that were causing errors, I got to:

ERROR: Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.10

The fix of replacing deprecated library with koptlin-stdlib-jdk7 is given in https://stackoverflow.com/questions/53448450/how-to-resolve-error-failed-to-resolve-org-jetbrains-kotlinkotlin-stdlib-jre7

And I got to "Hello World" on the app again. I was even able to include the line: import org.opencv.aruco.CharucoBoard in the MainActivity.kt file once I had established the module dependency on opencv4_1_0_contrib.

Then I made a completely clean install of my project from the repo https://github.com/Future-Hangglider/Hanglog3 (removing the module depdendencies), did a File New Import Module from the upgraded and working opencv4_1_0_contrib, and hit the same ERROR: Plugin with id 'com.github.dcendents.android-maven' not found.

But then I found a some extra lines in the build.gradle files of the Hello World working app and ported them to my dependencies section:

   classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
   classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

And then I got this:

ERROR: Could not get unknown property 'bintray_user' for object of type com.jfrog.bintray.gradle.BintrayExtension.

Now, there are a lot of $binTray variables under the opencv4_1_0_contrib module in the Project structure.

This had me stumped, until I discovered more lines at the bottom of the Hello World app build.gradle file:

if (!project.hasProperty("bintray_user")) {
    ext.bintray_user = "stub"
}

if (!project.hasProperty("bintray_apikey")) {
    ext.bintray_apikey = "stub"
}

if (!project.hasProperty("bintray_gpg_password")) {
    ext.bintray_gpg_password = "stub"
}

Now it compiles, build, links, deploys, and crashes with the following:

java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_zeros(int, int, int) (tried Java_org_opencv_core_Mat_n_1zeros and Java_org_opencv_core_Mat_n_1zeros__III)

I thought that when the AndroidStudio put the app together and says it is good to go, it's good to go. Apparently not.

It ran when I commented out all my OpenCV function calls it ran, except for the fact that OpenCVLoader.initDebug() is false.

The same is true when I went back to the Hello World app and inserted the line

   Toast.makeText(getBaseContext(), "OpenCVLoader " + (OpenCVLoader.initDebug()).toString(), Toast.LENGTH_LONG).show()

Am I missing something where you have to know what to do with the cmake files in opencv4_1_0_contrib/native/jni/abi-arm64-v8a ?

The official downloaded copy of OpenCV (without the contrib Aruco module that I need) contains a file opencv-4.1.2-android-sdk/OpenCV-android-sdk/sdk/native/libs/arm64-v8a/libopencv_java4.so that is missing from the quickbirds directory tree.

How does it get built?

nasirky commented 4 years ago

@goatchurchprime Thank you for taking interest in our repo. I am really sorry that we could not get back to you earlier. Are you still facing this issue and interested in a solution. If so, we would be glad to help.

nasirky commented 4 years ago

@goatchurchprime I would now close this issue. If you still need help, please open a new issue.