Skip to content

SDK Tools, Revision 25.3.0 and OpenCVDetectAndroidSDK.cmake #8460

Closed

Description

@mishurov
System information (version)
  • OpenCV => 3.2.0
  • Operating System / Platform => Gentoo / Android
  • Compiler => Android NDK toolchain gcc
Detailed description

OpenCVDetectAndroidSDK.cmake doesn't detect an Android SDK after updating to the SDK Tools, Revision 25.3.0.

--     SDK target:                  android_sdk_target_status-NOTFOUND
--     android tool:                NO
~/Android/Sdk/tools/android
The android command is no longer available.
For manual SDK and AVD management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager

An older version of the tools just werks.

https://developer.android.com/studio/releases/sdk-tools.html

SDK Tools, Revision 25.3.0 (March 2017)
...
Obsolete/deprecated tools have been removed:
android
ddms (instead see Using DDMS)
draw9patch (instead see Draw 9-patch)
hierarchyviewer (instead see Profile Your Layout with Hierarchy Viewer)
traceview (instead see Profiling with Traceview and dmtracedump)
ant scripts
Project and activity templates

Steps to reproduce
  1. Update SDK tools using an Android Studio
  2. Try to build an OpenCV for Android with Java wrappers and examples support.

alalek:

Current solution is to downgrade SDK Tools to the latest available version prior 25.3.0: 25.2.5. Direct download links are:

Activity

  1. diroitman commented on Apr 5, 2017

    @diroitman

    Hi

    I'm also interested - so how do you build opencv for android platform?
    I tried platform/android/build_sdk.py script and it gives me the same error

    Thank you

  2. mishurov commented on Apr 5, 2017

    @mishurov
    Author

    Gentoo has the old versions of the SDK with the working "android" tool. I set an environment variable with the path to the old version instead of the user directory where Android Studio installs recent versions of the SDK.
    https://packages.gentoo.org/packages/dev-util/android-sdk-update-manager

  3. adamajohnston commented on Jul 8, 2017

    @adamajohnston
  4. peterchaula commented on Aug 11, 2017

    @peterchaula

    I solved this by using ndk-r9 and tools at links provided by @adamajohnston but ran into other problems with 64 bit ABIs

  5. mishurov commented on Aug 16, 2017

    @mishurov
    Author

    @victorv, it's a workaround and half-measures, not a solution.

  6. peterchaula commented on Aug 16, 2017

    @peterchaula

    @victorv an older version of CMake is also required for that to build correctly

  7. hoonkai commented on Jan 1, 2018

    @hoonkai

    Is there any plan to have this issue looked at? Tools is already r27 now.

  8. peterchaula commented on Apr 11, 2018

    @peterchaula

    @NGriffiths you need to strip out intel threading libs (TBB). That'll shave off ~15MB off your library.

  9. alalek commented on Apr 11, 2018

    @alalek
    Member

    I observed significant size increase of OpenCV4Android package during preparation of #10515:

    BTW, Binaries size of OpenCV Android SDK with NDK r16 is about ~3Gb (NDK r10 ~800Mb). Most part of this impact is related to static .a files

    This is result of switching from NDK r10e -> 16b.

  10. WargnierP commented on May 9, 2018

    @WargnierP

    Unfortunately, this fix does not seem to do the trick for me: I can compile but the sdk/java folder and its content does not get created, making my build useless since it is required to import OpenCV in the projet. This seems to be linked to building the Android projects, which I had to disable for the configuration to go through. After many trials and errors to resolve all the configure errors CMake gave me, I ended up being stuck with
    CMake Error at cmake/android/android_ant_projects.cmake:40 (message): Android: List of installed Android targets is empty Call Stack (most recent call first): cmake/android/OpenCVDetectAndroidSDK.cmake:202 (include) CMakeLists.txt:649 (include)

    I am on a windows 10 system with OpenCV 3.4.1, Android studio 3.1.2, CMake 3.11.0, NDK r16, Android build tools 27.0.3 and 25.0.3 and I downloaded the Android tools 25.2.3 as indicated here, which I explicitely told CMake to use by creating the "ANDROID_SDK_TOOLS" variable manually. However, ANDROID_SDK variable points to my Android Studio SDK install, which is version the latest version.

    I have to mention that I also had to add the following variables manually, with the following configurations:

    • ANDROID_NATIVE_API_LEVEL 27
    • ANDROID_PROJECTS_BUILD_TYPE ANT

    I also tried selecting ANDROID_SDK_BUILD_TOOLS_VERSION between 27.0.3 and 25.0.3. But that did not change a thing. Lastly, I have to mention that, so far, I have only tried compiling for armeabi_v7a.

    Does anyone know what can cause the issue I'm having and how to fix it?

    Also, I noticed that CMake created the "ANDROID_SDK_TARGET" variable, but I don't know what value I should give it. Should I have to specify it manually, because I read nothing about that anywhere? What value should I give it?

    Could the issue be caused by a mismatch between the tools and build-tools version? If so, what is the build-tools version compatible with the 25.2.3 tools version?

    Any help is appreciated. Thanks in advance.

  11. alalek commented on May 9, 2018

    @alalek
    Member

    @WargnierP What Android platforms did you installed?

    $ ll /opt/android/android-sdk-linux/platforms/
    drwxrwxr-x 6 alalek alalek 4096 Feb  4  2015 android-10
    drwxrwxr-x 5 alalek alalek 4096 Feb  5  2015 android-18
    drwxrwxr-x 5 alalek alalek 4096 Feb  5  2015 android-21
    
  12. WargnierP commented on May 14, 2018

    @WargnierP

    Hi @alalek , I have installed Android Platforms 24, 25 and 27. Should I install other versions ?

  13. robertwgh commented on Jun 9, 2018

    @robertwgh

    @NGriffiths thanks for the info.
    ANDROID_STL="libc++_shared" should be ANDROID_STL="c++_shared"

  14. xindongzhang commented on Sep 4, 2018

    @xindongzhang

    I solve this problem by enable building java and android examples, following is my scripts:

    cmake -G "Unix Makefiles" -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DWITH_NEON=ON -DWITH_EIGEN=ON -DWITH_OPENCL=ON -DBUILD_opencv_gpu=OFF -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK/prebuilt/linux-x86_64/bin/make -DANDROID_ABI=arm64-v8a -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.3/modules -DBUILD_opencv_xfeatures2d=OFF -DBUILD_opencv_ximgproc=OFF -DBUILD_opencv_java=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCXXFLAGS="-Wall -fpu=neon -O3" -DBUILD_JAVA=OFF -DBUILD_ANDROID_EXAMPLES=OFF ../..
    
    

    actually, you only need to set -DBUILD_JAVA=OFF -DBUILD_ANDROID_EXAMPLES=OFF

  15. StainlessStlRat commented on Oct 6, 2018

    @StainlessStlRat

    So many people are successfully building the lib for c++_static/shared. Why on EARTH hasn't there been an SDK4Android commit with the new binaries?

  16. alalek commented on Oct 6, 2018

    @alalek
    Member

    Additional info about c++_static/shared limitations: https://developer.android.com/ndk/guides/cpp-support
    GCC (and its libs) has beed removed from Android NDK r18: https://developer.android.com/ndk/downloads/revision_history

    Current OpenCV builds use outdated Android NDK 10e and based on Eclipse Ant build.xml projects (it was actual for first OpenCV 3.0 release).
    Need to update Android build deps before next major OpenCV release.

  17. hannesa2 commented on Oct 7, 2018

    @hannesa2
    Contributor

    An other important hint here is:

    The Play Store will require 64-bit support when uploading an APK beginning in August 2019. Start porting now to avoid surprises when the time comes. For more information, see this blog post.

  18. crazyhappygame commented on Oct 9, 2018

    @crazyhappygame

    @alalek are there any ticket for:

    1. opencv and Android NDK r18
    2. opencv and Android 64 bits
  19. mishurov commented on Oct 9, 2018

    @mishurov
    Author

    Why don't you contact with googlers/jetbrainers and make that done in the case the problem is on their side. I don't like either that they push a lot into the Studio and make it harder for vim, react, etc.

  20. Howave commented on Oct 30, 2018

    @Howave

    Thank you to everyone for your help.

    I recently had to build OpenCV for Android from source (because I wanted to link against LLVM libc++ STL instead of GNU STL). In case it’s useful to anyone else, here are some quick instructions on how I did it:

    • $ mkdir ~/sdk && cd ~/sdk

    • $ wget https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip && unzip tools_r25.2.5-macosx.zip

    • $ tools/android sdk

    • Select and install the following two packages:

      • Android SDK Build-tools 27.0.3
      • Android 8.1.0 (API 27) -> SDK Platform 27
    • $ mkdir ~/opencv && cd ~/opencv

    • $ git clone https://github.com/opencv/opencv.git

    • $ cd ~/opencv/opencv

    • $ wget https://gist.githubusercontent.com/ngriffiths/296e2fc16b8586705712d50bdfe746b0/raw/350a8cb6497bfe367dda75b7bb202d6c7ce09a72/always-use-ant__find_android.patch && git apply always-use-ant__find_android.patch

    • $ cd platforms/android

    • $ ANDROID_SDK=~/sdk ANDROID_HOME=~/sdk ./build_sdk.py --config ndk-16.config.py ~/opencv/build

    I already had the ANDROID_NDK environment variable set to a local NDK 16 installation.

    To compile against libc++, I then changed ANDROID_STL="gnustl_static" in build_sdk.py to ANDROID_STL="libc++_shared" and ran build_sdk.py again.

    One unusual thing I couldn’t work out was why the static libs I built were much larger than those in the official distribution (e.g. my arm64-v8a/libopencv_core.a is 75.8MB vs 7.5MB).

    you can modify your ${ANDROID_NDK}/build/cmake/android.toolchain.cmake,remove "-g" debug flag, then the static libs size will be reduced

  21. Howave commented on Oct 30, 2018

    @Howave

    my build cmd is as below(ndk-r17c):
    cmake -GNinja -DINSTALL_ANDROID_EXAMPLES=OFF -DANDROID_EXAMPLES_WITH_LIBS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DWITH_OPENCL=OFF -DWITH_TBB=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_static -DANDROID_SDK_TARGET=19 -DBUILD_ANDROID_PROJECTS=ON -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON -DANDROID_PROJECTS_BUILD_TYPE=ANT ..

    ninja -j8

    ninjia install

  22. StainlessStlRat commented on Oct 30, 2018

    @StainlessStlRat

    Has anyone been able to get it to work with a lower SDK flag? Say sdk level 15?

  23. wernerd commented on Nov 4, 2018

    @wernerd

    @Howave Which SDK did you use to build opencv with r17c? The old 25 setup with the 'android' command line tool or the new one - 26.1.1?

    Actually 26.1.1 has an 'android' command line tool which simulates a small part of the 'android sdk' functions: list and update, but not create. IMHO OpenCV does not really need the 'android' command, only to support the Eclipse Android setup for the SDK part? Or do I miss something here?

  24. Howave commented on Nov 4, 2018

    @Howave

    @Howave Which SDK did you use to build opencv with r17c? The old 25 setup with the 'android' command line tool or the new one - 26.1.1?

    Actually 26.1.1 has an 'android' command line tool which simulates a small part of the 'android sdk' functions: list and update, but not create. IMHO OpenCV does not really need the 'android' command, only to support the Eclipse Android setup for the SDK part? Or do I miss something here?

    sdk-platform 28.0.1 with sdk-tool 26.1.1,
    then I remove the sdk-tool 26.1.1 and replace with 25

  25. alalek commented on Dec 7, 2018

    @alalek
    Member

    There is initial migration on gradle builds: #13386
    Review and suggestions are welcome!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: build/installfeaturefutureplatform: android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions