我正在尝试将c ++本机项目添加到我的库项目中。
我已关注this教程
我得fatal error: 'sys/sysctl.h' file not found
无法弄清楚原因。
我已按照以下步骤操作:
1)创建一个JNI
文件夹,并将所有源文件和包装器放在那里
2)创建了CMakeLIsts.txt
这是我的CMakeLIsts.txt
:
cmake_minimum_required(VERSION 3.4.1)
add_library(pHash-jni SHARED
pHash-jni.cpp)
target_link_libraries(pHash-jni log android)
3)将我的local.propreties
更新为:
ndk.dir=/home/maxim/Android/Sdk/ndk-bundle
sdk.dir=/home/maxim/Android/Sdk
4)将build.gradle更新为:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
cppFlags "-fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/jni/CMakeLists.txt"
}
}
productFlavors {
arm7 {
// in the future, ndk.abiFilter might also work
ndk {
abiFilter 'armeabi-v7a'
}
}
arm8 {
ndk {
abiFilters 'arm64-v8a'
}
}
arm {
ndk {
abiFilter 'armeabi'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
mips {
ndk {
abiFilters 'mips', 'mips64'
}
}
all {
ndk {
abiFilters 'mips', 'mips64', 'x86', 'x86_64'
}
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jni/'] } }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
5)将gradle.properties更新为:
android.useDeprecatedNdk=true
答案 0 :(得分:1)
$ find android-ndk-r13/platforms/ -name sysctl.h
../../android-ndk-r13/platforms/android-19/arch-arm/usr/include/linux/sysctl.h
more of the same...
Android没有<sys/sysctl.h>
,但确实有<linux/sysctl.h>
。