You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|| Philipp Hasper on 2015-05-28 11:31
|| Priority: Normal
|| Affected: None
|| Category: android
|| Tracker: Feature
|| Difficulty:
|| PR:
|| Platform: None / None
Support for Android Studio
Android Studio is now the official supported way for developing Android apps - the Eclipse integration is deprecated.
We need to migrate the Android tutorials / Android build chain to Android Studio.
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.
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.
@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.
So we are still waiting for community developers willing to add gradle support to OpenCV.
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:
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 -
./build.sh - makes arm7 and arm8 targets by default install.android.debug and install.android.release contain studio compatible installs - just move this into your project under an opencv directory and include into your project using the template at -
opencv/platforms/android/template/opencv-lib/
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?
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.
Eg when I make a improvement PR to use 3.4.0 I will make a fork of a fork.... this should happen in upstream repo !
@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).
Successfully assembled this sample with "armeabi-v7a" ABI (runs well on Android 4.3 device).
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 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.
Activity
PhilLab commentedon Sep 29, 2015
Is this planned for OpenCV 3.0.1?
hauptmech commentedon Nov 11, 2015
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.
PhilLab commentedon Nov 11, 2015
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.
hauptmech commentedon Nov 11, 2015
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.
PhilLab commentedon Nov 11, 2015
@hauptmech: is it possible for you to create a pull request containing that?
hauptmech commentedon Nov 11, 2015
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.
hauptmech commentedon Nov 14, 2015
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/
PhilLab commentedon Jul 14, 2016
@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.
mshabunin commentedon Jul 14, 2016
@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.
So we are still waiting for community developers willing to add gradle support to OpenCV.
7 remaining items
lxdatgithub commentedon Feb 9, 2017
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!
victorv commentedon Apr 19, 2017
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.
steveccable commentedon Jun 19, 2017
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.
victorv commentedon Jun 19, 2017
@steveccable - our tree is up to date with 3.2.0 and it's easy to build -
./build.sh- makes arm7 and arm8 targets by defaultinstall.android.debugandinstall.android.releasecontain studio compatible installs - just move this into your project under an opencv directory and include into your project using the template at -opencv/platforms/android/template/opencv-lib/We migrated the template to the latest stable gradle but it's not pushed to GitHub.
bendaf commentedon Jul 26, 2017
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?
floe commentedon Nov 1, 2017
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 ?
floe commentedon Dec 22, 2017
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.
hannesa2 commentedon Dec 29, 2017
@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.
Eg when I make a improvement PR to use 3.4.0 I will make a fork of a fork.... this should happen in upstream repo !
victorv commentedon Dec 29, 2017
@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.
alalek commentedon Jan 1, 2018
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).
Successfully assembled this sample with "armeabi-v7a" ABI (runs well on Android 4.3 device).
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.
victorv commentedon Jan 1, 2018
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.
vladimir-dudnik commentedon Sep 26, 2019
is that still actual?
floe commentedon Sep 26, 2019
No, I think this can be closed, 4.0+ works fine with Gradle/AS.
vladimir-dudnik commentedon Sep 26, 2019
@floe thanks for update. I'll close this issue.