我观看了视频 http://ph0b.com/android-studio-gradle-and-ndk-integration/
看起来我的问题出在我的build.gradle和Android.mk文件中
我正在尝试将预构建的库(.so)集成到Android NDK中。 - 我创建了一个src / main / jni - 我放了所有的.cpp文件 - 我也有src / main / jniLibs目录,我有每个架构的.so文件。 - 我已将local.properties指向我的sdk和我的ndk目录。 - 我知道Android会在debug目录下创建一个Android.mk文件,并在每个架构的src / main / libs中创建一个libs文件夹。 _我正在使用带有sdk 19.1的Android Studio 1.01。我在libs目录下看到armeabiv7a和armeabi。我猜测Android创建了这些库。
**我收到以下错误: FAILURE:构建因异常而失败。 * 什么地方出了错: 任务':app:buildNative'执行失败。
处理'命令'Documents / android_development / android-ndk-r10d / ndk-build''以非零退出值2结束 *尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。**
我的问题是: - 我的jni目录中是否需要我的Android.mk文件版本? - 我知道我必须修改build.gradle,我在这里缺少什么? - 我想使用intel HAXM测试模拟器。 如何使用mac查看intel HAXM的cFlags。
我的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'android'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com....soundtouchexamplewithseekbar"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
// .. android settings ..
productFlavors {
x86{
ndk {
abiFilter "x86"
stl "gnustl_shared"
moduleName "soundtouch-jni"
// cFlags "-mtune=atom -mssse3 -mfpmath=sse"// Define some macros
// cFlags "-DANDROID_NDK -D_DEBUG DNULL=0"
cFlags "-std=c++11"
// ldLibs "GLESv3", "dl", "log"
ldLibs "log", "z", "m"
}
}
arm {
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
stl "gnustl_shared"
moduleName "soundtouch-jni"
cFlags "-DANDROID_NDK -D_DEBUG DNULL=0" // Define some macros
ldLibs "EGL", "GLESv3", "dl", "log"
}
}
armv7{
ndk {
abiFilter "armeabi-v7a"
stl "gnustl_shared"
moduleName "soundtouch-jni"
cFlags "-DANDROID_NDK -D_DEBUG DNULL=0" // Define some macros
ldLibs "EGL", "GLESv3", "dl", "log"
}
}
mips {
ndk {
abiFilter "mips"
moduleName "soundtouch-jni"
stl "gnustl_shared"
cFlags "-DANDROID_NDK -D_DEBUG DNULL=0" // Define some macros
ldLibs "EGL", "GLESv3", "dl", "log"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main']
res.srcDirs = ['src/main/res']
jniLibs.srcDirs = ['src/main/jniLibs']
jni.srcDirs = [] // This prevents the auto generation of Android.mk
}
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK')
{
def ndkDir = android.plugin.ndkFolder
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
// Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'-d',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.plugin.ndkFolder
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
// Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
====== 我的Android.mk:
LOCAL_PATH := $(call my-dir)
#LOCAL_CPP_FEATURES += -fno-exceptions commented Jan 28th
include $(CLEAR_VARS)
# *** Remember: Change -O0 into -O2 in add-applications.mk ***
# MODIFICATION START
MY_SOURCE_DIR :=
<I have source dir here with full path >
# MODIFICATION END
LOCAL_MODULE := soundtouch-jni
LOCAL_SRC_FILES := soundtouch-jni.cpp $(MY_SOURCE_DIR)/AAFilter.cpp
# for native audio
#LOCAL_LDLIBS += -lgcc
LOCAL_LDLIBS += -lz #added jan 28th
LOCAL_C_INCLUDES += $(LOCAL_PATH)/soundtouch/include
# --whole-archive -lgcc
# for logging
LOCAL_LDLIBS += -llog
# for native asset manager
#LOCAL_LDLIBS += -landroid
# don't export all symbols
# added "-marm" switch to use arm instruction set instead of thumb for improved calculation performance.
# removed -marm here as I was getting error while building x86 instruction -jan 19,2014
LOCAL_CFLAGS += -Wall -fvisibility=hidden -I $(MY_SOURCE_DIR)/../../include -D ST_NO_EXCEPTION_HANDLING -fdata-sections -ffunction-sections
如果我的理解不对,请纠正我。我观看了视频,这是我在发布问题之前做的第一件事。这是最好的视频之一。我认为做gradle的重点是避免这种手动构建。我已经在我的
中加入了ndk-buildtask buildNative(type: Exec, description: 'Compile JNI source via NDK')
{
def ndkDir = android.plugin.ndkFolder
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
// Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'-d',
'NDK_DEBUG=1'
}
我想知道是否必须在build.gradle或Android.mk中添加任何语句。谢谢!