我正在使用Android studio 3.1.2。在官方文档中(向您的项目添加 C 和 C++ 代码)
没有使用ndk-build的方式。它似乎更喜欢CMake.And当我使用ndk-build时,配置如下: 模块级别的build.gradle:
compileSdkVersion 25
defaultConfig{
ndk {
moduleName "telephone"
cFlags "-fexceptions"
ldLibs "log","z","m"
stl "stlport_static"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
externalNativeBuild {
ndkBuild {
// path "$projectDir/jni/Android.mk"
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi","arm64-v8a","x86"
cppFlags "-frtti -fexceptions"
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ["src/main/jniLibs"]
jni.srcDirs = ["src/main/jni"]
}
}
buildToolsVersion '27.0.3'
和Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := addcomputer
LOCAL_SRC_FILES := src/main/jni/addcomputer-jni.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
和Application.mk:
APP_ABI:=armeabi-v7a, arm64-v8a, x86, x86_64
APP_STL:=stlport_shared
APP_CPPFLAGS += -fexceptions
但无论我如何更改配置,构建行为都会返回如下错误:
Error: Your project contains C++ files but it is not using a supported
native build system.
Consider using CMake or ndk-build integration. For more information, go to:
https://d.android.com/r/studio-ui/add-native-code.html
Alternatively, you can use the experimental plugin:
https://developer.android.com/r/tools/experimental-plugin.html
并参考此官方网页ndk-build 我已经安装了GNU Make 3.81,并导出了GNUMAKE,但是没有用。 我在互联网上找到了很多参考资料,虽然我像他们说的那样配置,但是错误仍然存在。我不知道该怎么做。我需要使用Android.mk和ndk-build。因为这个网页说: Generating C++ Binder Interfaces with aidl-cpp
任何人都可以提供帮助吗?请