-
-
Notifications
You must be signed in to change notification settings - Fork 55.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Android Studio #5003
Comments
Is this planned for OpenCV 3.0.1? |
I have been having a very unpleasant experience getting opencv and android development to work. I'm new to android and the java toolchain. I'd be really happy with a commandline walkthrough of getting any opencv native sample running with gradle+ndk-build. An android studio example would be ok too but that seems to be a moving target right now. |
Yeah, the "these tutorials are for Eclipse but are easily reproducable with Android Studio"-sentence at the beginning of many new Android OpenCV tutorials seems rather cynical 😉 It does work but it is by no means easy if you are new to Gradle. |
12 hours to get tutorial-2-mixedprocessing to build and run. Having OpenCV 2.4 and an Arm64 device did not help things, but most of my time was figuring out a working combination of android studio, android_ndk, gradle-experimental vs gradle plugins, and viable imports of the samples (or gradle layout remappings). The most useful thing you guys could do is add gradle files to the samples. At least one could build them and start learning from them then. |
@hauptmech: is it possible for you to create a pull request containing that? |
Don't have time. Also anything I came up with would be nothing close to best practice which is what you want for a sample. You will need to decide whether to support ndk-build or android-studio with gradle-experimental plugin. |
I revisited the OpenCV samples as prep to tackle the ROS android stuff. Using gradle-experimental and an in-situ build.gradle file for the library worked well for me. Possibly neither are best practice but after a couple days of working with this as a beginner, I can say that this approach is much easier to wrap my head around than the Import-to-android-studio way which has generally unreliable documentation and seems to change every few months. I jotted down what I did here: http://hauptmech.github.io/OpenCV1/ |
@mshabunin Would this also be an issue for milestone 3.2 ? Maybe the priority could be increased as well - Android Studio is quite mature now. |
@PhilLab , unfortunately the core team does not have enough Android experts to help with this feature at this moment. Milestone 3.2 is intended to collect several reproducible and/or simple bugs to be fixed during summer hackathon, it does not mean that other issues will not be fixed before 3.2. |
Okay, what a pity. Thanks for the response, though! |
Hello ! |
Hi @PopTudor , please make a PR. |
@apavlenko I'm not sure how to integrate the branch because I downloaded the samples from original site and sourceforge instead of forking from git :( . I pushed the sample here: https://github.com/PopTudor/face-detection-Android-Studio . I'll leave them here temporarily or try to integrate them if you have any idea how. To run the sample you need at least Android Studio 2.2 Beta 2 and then 'Open an existing Android Studio project'. I think it would be a good idea to wait at least a stable version of AS 2.2 before porting the samples |
I can help with Android / Gradle and development issues, so I guess someone from the project core let me know what is needed. To earlier comments by folks like @PhilLab and @hauptmech , Gradle support for NDK + Android Plugin has been a long time coming, like 4+ years (ridiculously long), so it's taken a long time for the Android community to switch over to using Gradle for JNI development, despite there being claims that Gradle/Android Plugin/NDK were all working well together. @PopTudor I'll look at your branch. |
@truedat101 awesome! Android Studio 2.2 is also stable now and future updates should not break the samples. They also updated their tutorials/documentation on NDK and CMake integration with Gradle. Hope it helps. |
Add this code to the openCVSamplefacedetection build.gradle, in my case ,it works.
In this case , the environment is android studio 2.2.3 , opencv 3.2.0. In the new verison of android studio, the C++ support is so sweet. You right click the any directory in your project,like "cpp" or so-called "jni" directory in your project, that will a option "Link C++ Projects with Gradle" ,click it and choose ndk-build, then point to your Android.mk which is in "cpp" directory(/home/user/AndroidStudioProjects/face-detection/openCVSamplefacedetection/src/main/jni). That will add the code above to the build.gradle. Lukily , you can also choose cmake if you have CMakeList.txt file. By the way , you would better export the OPENCV_ANDROID_SDK to the sys variable before compiling the opencv sample project, like below:
Enjoy the new android studio and opencv! |
We have a working android studio build in our fork here https://github.com/10imaging/opencv It currently uses gradle-experimental for the enhanced native debug support but it can also integrate into standard gradle. Let me know if there is any interest and I can provide a sample AS app to show how to easily integrate it into any app. |
Is there any word on when/if this support should be integrated into OpenCV proper? It looks like people are getting it working in their own projects (see above comment), but the last activity I see on here of someone trying to get it into the main project was a volunteer last September with no responses to his comment. |
@steveccable - our tree is up to date with 3.2.0 and it's easy to build -
We migrated the template to the latest stable gradle but it's not pushed to GitHub. |
please create a how to page or a tutorial or example or anything. It is not so obvious for me - an android developer new to openCV - how should I integrate it to my project. Nobody uses eclipse for android development any more and I can't find an opncv example working with android studio right after import. Where do I find ./build.sh? what is install.android.debug/release, a directory? |
FWIW, I've just ported tutorial-2-mixedprocessing to native Gradle 3 & CMake, which was pretty straightforward (half an afternoon). I'd be interested to work on this and submit a PR, but I don't have a very good overview how the Android SDK package is actually built. I'm assuming this is mostly done by https://github.com/opencv/opencv/blob/master/platforms/android/build_sdk.py ? |
Addendum: I've built a "proper" Android Studio package from the official Android SDK. Package is available at https://github.com/floe/opencv-android, just wanted to suggest that this link may be useful for people reading here. I've also enabled JitPack for this repo, so now the OpenCV SDK can be pulled into any Android Studio project by adding two lines to the Gradle build files. |
@victorv your fork looks very promising. Please can you add some lines in README.md to see what's better and how to use it. And what's about to make a PR to have it in main upstream repo, I guess I've not to explain what's the benefit, when there is not that much fragmentation out there. |
@hannesa2 it will need some work to make it useful for a pull request. We are currently testing 3.4.0 with our fork and we will push that change soon which will also have an alternate way to deal with creating an Android compatible library. |
I prepared build.gradle script to use OpenCV in your apps with prebuilt OpenCV Android SDKs (should work with OpenCV 3.4, just put this file into "sdk" subdirectory and follow notes). Based on behavior / project templates of Android Studio 3.0.1 (171: Nov 9, 2017). Any feedback / suggestions / fixes based on your Android's development experience are welcome (here or via Gist comments). Note: Building OpenCV for Android itself is out of scope of the proposed script. |
We have a working build system for OpenCV Android and a template working with the latest Android Studio and Gradle versions here - https://github.com/10imaging/opencv/tree/master/platforms/android/template/opencv-lib We decided to bypass the android tool for making a compatible android library template and just keeping our template up to date against the latest tools. Fewer dependencies on Android tool set is more desirable as they seem to drop features on a whim. |
is that still actual? |
No, I think this can be closed, 4.0+ works fine with Gradle/AS. |
@floe thanks for update. I'll close this issue. |
Transferred from http://code.opencv.org/issues/4366
Support for Android Studio
History
The text was updated successfully, but these errors were encountered: