Build migration to use cmake

I am moving the project from gradle -experimental: 0.8.3 to gradle: 2.3.3. Along with this, I also need to start using the new cmake, which is not so straightforward. A fragment of an experimental gradle plugin that worked:

repositories { libs(PrebuiltLibraries) { // Configure one pre-built lib: shared crypto { // Inform Android Studio where header file dir for this lib headers.srcDir "${lib_distribution_root}/openssl/includes" // Inform Android Studio where lib is -- each ABI should have a lib file binaries.withType(SharedLibraryBinary) { sharedLibraryFile = file("${lib_distribution_root}/openssl/lib/armeabi/libcrypto.so") } } openssl { // Inform Android Studio where header file dir for this lib headers.srcDir "${lib_distribution_root}/openssl/includes" // Inform Android Studio where lib is -- each ABI should have a lib file binaries.withType(SharedLibraryBinary) { sharedLibraryFile = file("${lib_distribution_root}/openssl/lib/armeabi/libssl.so") } } pjsip { // Inform Android Studio where header file dir for this lib headers.srcDir "${lib_distribution_root}/pjsip/includes" // Inform Android Studio where lib is -- each ABI should have a lib file binaries.withType(SharedLibraryBinary) { sharedLibraryFile = file("${lib_distribution_root}/pjsip/lib/armeabi/libpjsua.so") } } } } android { def globalConfiguration = rootProject.ext compileSdkVersion = globalConfiguration.androidCompileSdkVersion buildToolsVersion = globalConfiguration.androidBuildToolsVersion defaultConfig.with { minSdkVersion.apiLevel = globalConfiguration.androidMinSdkVersion targetSdkVersion.apiLevel = globalConfiguration.androidTargetSdkVersion multiDexEnabled = true testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } dexOptions.with { javaMaxHeapSize = "4g" } lintOptions.with { abortOnError = false } sources { main { jni { dependencies { library 'crypto' linkage 'shared' library 'openssl' linkage 'shared' library 'pjsip' linkage 'shared' } } jniLibs { // for shared lib, lib need to be pushed to the target too // Once libs are copied into app/src/main/jniLibs directory, // Android Studio will pack them into APK lib/ directory // Here we like to avoid another duplication by pointing // to the files that containing our libs' distribution location // so the same file is used by compiler at host, also packed // into APk to be used at Target (phone/tablet) source { srcDir "${lib_distribution_root}/openssl/lib/armeabi" srcDir "${lib_distribution_root}/pjsip/lib/armeabi" } } } } ndk { moduleName = "datanative" platformVersion = 19 stl = "gnustl_static" ldLibs.addAll("android", "stdc++", "log", "GLESv2", "EGL", "OpenSLES", "z", "m") cppFlags.addAll("-std=c++11", "-frtti", "-fexceptions", "-pthread", "-fpic", "-ffunction-sections", "-funwind-tables") cppFlags.add("-DPJ_AUTOCONF") abiFilters.add(abiName) cppFlags.add("-marm") } } 

}

Current work in progress has a gradle configuration:

 android { def globalConfiguration = rootProject.ext compileSdkVersion globalConfiguration.androidCompileSdkVersion buildToolsVersion globalConfiguration.androidBuildToolsVersion defaultConfig { minSdkVersion globalConfiguration.androidMinSdkVersion targetSdkVersion globalConfiguration.androidTargetSdkVersion multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-std=c++11", "-DPJ_AUTOCONF", "-fpic", "-frtti", "-fexceptions", "-pthread", "-ffunction-sections", "-funwind-tables", "-marm" arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=gnustl_static' } } ndk { moduleName "datanative" abiFilters 'armeabi' } } externalNativeBuild { cmake { path 'CMakeLists.txt' } } sourceSets { main { jniLibs.srcDirs '../distribution/pjsip/lib/armeabi/', '../distribution/openssl/lib/armeabi/', 'src/main/cpp/' } } dexOptions.with { javaMaxHeapSize = "4g" } lintOptions.with { abortOnError = false } 

}

And CMakeLists:

 cmake_minimum_required(VERSION 3.4.1) file(GLOB SOURCES src/main/cpp/*.h src/main/cpp/*.cpp ) set(distribution_DIR ${path}) include_directories(src/main/cpp/) include_directories(../distribution/openssl/includes/) include_directories(../distribution/pjsip/includes/) add_library( crypto SHARED IMPORTED ) set_target_properties(crypto PROPERTIES IMPORTED_LOCATION # Provides the path to the library you want to import. absolute_path_cause_gradle_has_error_otherwise/distribution/openssl/lib/armeabi/libcrypto.so ) add_library( ssl SHARED IMPORTED ) set_target_properties(ssl PROPERTIES IMPORTED_LOCATION # Provides the path to the library you want to import. absolute_path_cause_gradle_has_error_otherwise/distribution/openssl/lib/armeabi/libssl.so ) add_library( pjsip SHARED IMPORTED ) set_target_properties(pjsip PROPERTIES IMPORTED_LOCATION # Provides the path to the library you want to import. absolute_path_cause_gradle_has_error_otherwise/distribution/pjsip/lib/armeabi/libpjsua.so ) add_library( data SHARED ${SOURCES} ) target_link_libraries(data crypto ssl pjsip) 

A communication error that I encountered, and perhaps not the main reason:

 /src/main/cpp/sthread.cpp Error:(73) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE' Error:(73) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE' /Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h Error:(547) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE' Error:(547) undefined reference to '__emutls_v._ZN6STrace12pLocalStreamE' 

Any hint would be appreciated. Thanks!

+5
source share

Source: https://habr.com/ru/post/1271234/


All Articles