morozRed
morozRed

Reputation: 176

Qt for Android on Mac or Linux build "Can not detect ndk toolchain..."

I have just installed SDK, NDK, JDK. When I type in Terminal:

moroz@moroz:~/qt/qt5$ ./configure -developer-build -opensource -confirm-license -xplatform android-g++ -nomake tests -nomake examples -android-ndk android-ndk-r9/ -android-sdk android-sdk-linux/ -android-ndk-host linux-x86_64 -android-toolchain-version 4.8 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples

Then

moroz@moroz:~/qt/qt5$ /home/moroz/qt/qt5/qtbase/configure -top-level -developer-build -opensource -confirm-license -xplatform android-g++ -nomake tests -nomake examples -android-ndk android-ndk-r9/ -android-sdk android-sdk-linux/ -android-ndk-host linux-x86_64 -android-toolchain-version 4.8 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples

I got the follwoing error:

Can not detect Android NDK toolchain. Please use -android-toolchain-version to specify

And there is the same message on Mac and Ubuntu!

Upvotes: 0

Views: 1760

Answers (4)

Ed of the Mountain
Ed of the Mountain

Reputation: 5469

  • On Android 5.0 and lower, QSslSocket will use Android system's libssl.so and libcrypto.ssl
  • On Android >= 6.0, your app must include it's own libssl.so and libcrypto.ssl
  • OpenSSL is not part of Qt installation due to legal restrictions in some countries.
  • You must consider enabling/disabling the SSL features based on legal restrictions in the region where your application is available.
  • See the SSL configure options for details about the configurable features
  • Do not use pre-built OpenSSL libs you find laying about the Internet.

1) How to Build OpenSSL On macOS:

To build OpenSSL Android libs for arm, arm-v7a, and x86 using a macOS host, this script works great if you use Android NDK r10e:

** Copy libs to your Qt app's project folder: **

platform/
└── android
    └── lib
        └── openssl
            ├── README.md
            ├── android-openssl-vsts.webloc
            ├── arch-armeabi-v7a
            │   ├── libcrypto.a
            │   ├── libcrypto.so
            │   ├── libssl.a
            │   └── libssl.so
            └── arch-x86
                ├── libcrypto.a
                ├── libcrypto.so
                ├── libssl.a
                └── libssl.so

2) Add to your Qt yourapp.pro project file:

android {
    # Android >= 6.0 requires apps to install their own libcrypto.so and libssl.so
    # https://subsite.visualstudio.com/DefaultCollection/android-openssl
    equals(ANDROID_TARGET_ARCH, armeabi-v7a) {
        ANDROID_EXTRA_LIBS += $$files($${PWD}/platform/android/lib/openssl/arch-armeabi-v7a/*.so)
    }
    equals(ANDROID_TARGET_ARCH, x86)  {
        ANDROID_EXTRA_LIBS += $$files($${PWD}/platform/android/lib/openssl/arch-x86/*.so)
    }
}

I wasted so much time trying to build OpenSLL on Linux and macOS until I found that script, and figured out I needed to build with Android NDK r10e or earlier.

The Qt Adding OpenSSL Support for Android guide did not work for me. However it may work if I had reverted to NDK r10e.

I hope this saves someone some time.

Upvotes: 0

lesyk
lesyk

Reputation: 4129

I my case I specified relative path to ndk - same error, after providing full path, it made its job.

Upvotes: 0

Markku
Markku

Reputation: 565

There is an issue in i7. It shows processor architecture as i386 (32bit), but hardware as x84_64 (64bit).

$ uname -p
i386

$ uname -m
x86_64

-m print the machine hardware name.

-p print the machine processor architecture name.

One must hack qtbase/configure file to return x86_64

 macx-g++-64)
            PLATFORM=macx-g++
            NATIVE_64_ARCH=
            case `uname -p` in
            i386) NATIVE_64_ARCH="x86_64" ;;
            powerpc) NATIVE_64_ARCH="ppc64" ;;
            *)   echo "WARNING: Can't detect CPU architecture for macx-g++-64" ;;
            esac
            if [ ! -z "$NATIVE_64_ARCH" ]; then
                QTCONFIG_CONFIG="$QTCONFIG_CONFIG $NATIVE_64_ARCH"
            fi
            ;;
        esac

Another solution is to download 32bit Android NDK and use darwin-x86 as host name.

Upvotes: 0

pigiuz
pigiuz

Reputation: 192

on a mac you should use

-android-ndk-host darwin-x86_64

it resolvs -android-ndk-host in ndkfolder/prebuilt/ (I have darwin-x86_x64, android-arm, android-mips, android-x86, common)

Upvotes: 1

Related Questions