Skip to content

Build for Android

Luc edited this page Feb 12, 2024 · 44 revisions
  • Clone the GIT repository into a directory of your choice
  • Install the latest CMake. You need at least CMake Version 3.3.
  • Install the Android Studio:
    • from developer.android.com
      • Install with all options left as default.
      • Remember where the Android SDK gets installed (e.g. c:\Users???\AppData\Local\Android\sdk)
    • or with JetBrains Toolbox:
      • On the Welcome Screen choose first More Actions > SDK Manager to install first the latest Android SDK.
  • Startup Android Studio and choose Import project (Eclipse ADT, Gradle, etc.)
    • Choose the build.gradle file in the folder apps/app-Demo-SLProject/android
  • The SLProject demo app targets the Android SDK 24 (= Android 6.0)
    • If not installed the IDE gives you a link for all missing SDK versions.
    • The min. SDK needed is 21 (Android 5.0)
  • The SLProject uses the Android NDK (native development kit). If not installed:
    • Open the SDK manager with Tools > SDK Manager
    • Select the tab SDK Tools
      • Check the NDK option and click Apply
      • Check also the Google USB Driver option and click Apply
    • If the missing NDK error is still present, restart Android Studio and install possibly new package updates.
  • Build the project with Hammer button or with Build > Make Project (Ctrl-F9)
    • The app can only run on real but not on virtual devices because the prebuilt OpenCV libraries (_lib/prebuilt/Android) are only built for the arm architectures armeabi-v7a and arm64-v8a. To run the app in a virtual device you would have to build OpenCV also for Android on the x86 architecture.
  • After a successful build you can start the app on a USB-connected device by clicking the green start button.
    • If your device is not listed in the Deployment Targets dialog please check again your USB driver. In some cases, you have to download the appropriate driver from the device manufacturer.
  • Release Build:
    • Click on the left border the Build Variants tab.
    • Set the Active Build Variant to release.
    • in build.gradle edit the signingConfigs to set the password of the SLProject keystore.

` signingConfigs {

    release {

        keyAlias 'slproject-release-key'

        keyPassword '....' // Change to your key password

        storeFile file('../slproject-release-key')

        storePassword '....' // Change to your store password

    }

}

`

  • Choose Build -> Build bundle -> Build APK

Another way is to generate a new KeyStore

  • Choose Build > Generate Signed Bundle or APK and select APK.
    • Create or choose a signed keystone file in a secure file location.
    • Fill in the Key store password, Key alias and Key password and click Next.
    • Choose release and press Create. The APK gets signed and written to the destination folder.
  • Then modify the build.gradle to use your Keystore with the provided password.