AndroidStudio NDK编译配置_WIN32

AndroidStudio搭建好开发环境后,开始开发NDK,需配置NDK
1**.NDK build.gradle配置**
android {
compileSdkVersion 23
buildToolsVersion ‘23.0.3’

defaultConfig {
    minSdkVersion 18
    targetSdkVersion 23
//NDK编译方法1  NDK配置``
//ndk {
//	moduleName "libcamera"
//	abiFilters "armeabi", "armeabi-v7a"
//}
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
//SRC配置
sourceSets {
		main {
			jniLibs.srcDir 'src/main/libs'
			jni.srcDirs = []
		}
}
    //NDK编译方法1
    //externalNativeBuild {
    //    ndkBuild {
    //        path file("src/main/jni/Android.mk")
    //    }
    //}
    //NDK编译方法2
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
println('executing ndkBuild')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build.cmd", '-j2', '-C', file('src/main').absolutePath
}
task ndkClean(type: Exec, description: 'clean JNI libraries') {
println('executing ndkBuild clean')
def ndkBuildPath = android.ndkDirectory;
commandLine "$ndkBuildPath/ndk-build.cmd", 'clean', '-C', file('src/main').absolutePath
}
clean.dependsOn 'ndkClean'

/*
单线程:
//NDK编译方法
task buildNative(type: Exec, description: ‘Compile JNI source via NDK’) {
def ndkDir = android.ndkDirectory
commandLine “$ndkDir/ndk-build.cmd”,
‘-C’, file(‘src/main/jni’).absolutePath//jni 路径
}

task cleanNative(type: Exec, description: 'Clean JNI object files') {
    def ndkDir = android.ndkDirectory
    commandLine "$ndkDir/ndk-build.cmd",
            '-C', file('src/main/jni').absolutePath//jni路径
}

clean.dependsOn 'cleanNative'

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn buildNative
}

/
}
dependencies {
compile fileTree(dir: new File(buildDir, ‘libs’), include: '
.jar’)
}重点内容

2. src/main/jni Android.mk以及Application.mk配置 针对编译方法2

2.1
 Android.mk
 LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_C_INCLUDES += \
	$(LOCAL_PATH)/.. \
	$(LOCAL_PATH)/include

LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%)
LOCAL_EXPORT_LDLIBS := -llog

LOCAL_SRC_FILES := \
	empty.c

LOCAL_MODULE := libempty
include $(BUILD_SHARED_LIBRARY)

2.2 Application.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
APP_PLATFORM := android-19
APP_ABI := armeabi-v7a arm64-v8a
#APP_OPTIM := debug
#APP_OPTIM := release
include $(BUILD_EXECUTABLE)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

村里小码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值