我正在尝试使用CMAKE和Android Studio(2.3.2)生成静态库。以下是我的CMakeLists.txt的样子。我无法生成.a文件,但是当我将库更改为SHARED时,生成CMakeTestModule.so文件时会生成" Build-> Rebuild Project"。是否需要添加/设置任何用于构建STATIC库的标志。
cmake_minimum_required(VERSION 3.4.1)
project (CMakeTestProject)
include_directories(
src/main/cpp/
)
add_library(
CMakeTestModule
STATIC
src/main/cpp/CMakeTestModule.cpp
)
add_executable(
CMakeTestModule_test
src/main/cpp/CMakeTestModule_test.cpp
)
target_link_libraries(CMakeTestModule_test CMakeTestModule)
这就是我的build.gradle的样子:
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
externalNativeBuild {
cmake {
abiFilters 'armeabi'
}
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
答案 0 :(得分:0)
我通过在build.gradle中指定目标来修复此问题。像下面的东西。由于apk仅使用.so文件,因此我们需要提及静态库和可执行文件的目标。
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
externalNativeBuild {
cmake {
abiFilters 'armeabi'
}
targets "CMakeTestModule_test", "CMakeTestModule"
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}