3

Related to: build cmake ExternalProject with gradle

I'm trying to port an existing C++ project to Android (using Android Studio 3.0.1). The C++ project depends on a few other C++ packages. Since they all need to be cross-compiled for Android, I'm trying to execute a superbuild using CMake's ExternalProject (see a non-Android example here).

Calling <package>/gradlew assembleRelease should (AFAIK) compile everything, but it appears to only execute the CMake configuration step and doesn't actually call ninja to execute the build step, meaning none of the ExternalProjects are downloaded or built. In order to actually download and compile the ExternalProjects, I need navigate to <package>/app/.externalNativeBuild/cmake/<BUILD_TYPE>/<ABI> and manually call ninja. What am I doing wrong?

Here's my top-level CMakeLists.txt file:

cmake_minimum_required(VERSION 3.4.1)

include(ExternalProject)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
endif ()

# Forward Android CMake cross compile args to ExternalProject.
set(ANDROID_CMAKE_ARGS
  -DANDROID_ABI=${ANDROID_ABI}
  -DANDROID_PLATFORM=${ANDROID_PLATFORM}
  -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  -DANDROID_NDK=${ANDROID_NDK}
  -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
  -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
  -G${CMAKE_GENERATOR})

# Dependency.
ExternalProject_Add(eigen
  HG_REPOSITORY https://bitbucket.org/eigen/eigen
  HG_TAG 3.2.10
  CMAKE_ARGS ${ANDROID_CMAKE_ARGS})

# Main project that depends on Eigen.
ExternalProject_Add(main
  DEPENDS eigen
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main
  CMAKE_ARGS ${ANDROID_CMAKE_ARGS})

Here are relevant parts of my app/build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
}
tac-eibmoz
  • 31
  • 2

0 Answers0