我从gradle-experimental迁移项目:0.8.3到gradle:2.3.3。 除此之外,我还需要开始使用新的cmake,这证明不是那么直接。 实验性gradle插件的片段有效:
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's 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")
}
}
}
当前正在进行的工作有gradle配置:
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
}
}
和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)
我面临的链接错误,可能不是根本原因:
/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'
任何线索都会被贬低。 谢谢!