Skip to content

Support for Android Studio #5003

Closed
Closed

Description

@opencv-pushbot

Transferred from http://code.opencv.org/issues/4366

|| 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.

History

Activity

  1. PhilLab commented on Sep 29, 2015

    @PhilLab
    Contributor

    Is this planned for OpenCV 3.0.1?

  2. hauptmech commented on Nov 11, 2015

    @hauptmech

    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.

  3. PhilLab commented on Nov 11, 2015

    @PhilLab
    Contributor

    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.

  4. hauptmech commented on Nov 11, 2015

    @hauptmech

    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.

  5. PhilLab commented on Nov 11, 2015

    @PhilLab
    Contributor

    @hauptmech: is it possible for you to create a pull request containing that?

  6. hauptmech commented on Nov 11, 2015

    @hauptmech

    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.

  7. hauptmech commented on Nov 14, 2015

    @hauptmech

    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/

  8. PhilLab commented on Jul 14, 2016

    @PhilLab
    Contributor

    @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.

  9. mshabunin commented on Jul 14, 2016

    @mshabunin
    Contributor

    @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.

  10. 7 remaining items

  11. lxdatgithub commented on Feb 9, 2017

    @lxdatgithub

    Add this code to the openCVSamplefacedetection build.gradle, in my case ,it works.

        externalNativeBuild {
            ndkBuild {
                 path 'src/main/jni/Android.mk'
            }
        }
    
    

    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:

    export OPENCV_ANDROID_SDK=/home/user/AndroidStudioProjects/OpenCV-android-sdk
    

    Enjoy the new android studio and opencv!

  12. victorv commented on Apr 19, 2017

    @victorv

    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.

  13. steveccable commented on Jun 19, 2017

    @steveccable

    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.

  14. victorv commented on Jun 19, 2017

    @victorv

    @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.

  15. bendaf commented on Jul 26, 2017

    @bendaf

    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?

  16. floe commented on Nov 1, 2017

    @floe
    Contributor

    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 ?

  17. floe commented on Dec 22, 2017

    @floe
    Contributor

    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.

  18. hannesa2 commented on Dec 29, 2017

    @hannesa2
    Contributor

    @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 !

  19. victorv commented on Dec 29, 2017

    @victorv

    @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.

  20. alalek commented on Jan 1, 2018

    @alalek
    Member

    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.

  21. victorv commented on Jan 1, 2018

    @victorv

    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.

  22. vladimir-dudnik commented on Sep 26, 2019

    @vladimir-dudnik
    Contributor

    is that still actual?

  23. floe commented on Sep 26, 2019

    @floe
    Contributor

    No, I think this can be closed, 4.0+ works fine with Gradle/AS.

  24. vladimir-dudnik commented on Sep 26, 2019

    @vladimir-dudnik
    Contributor

    @floe thanks for update. I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions