修改maven仓库
repositories {
maven { url 'http://maven.oschina.net/content/groups/public/' }
mavenCentral()
}
使用Android.mk 编译JNI
AS目前已经可以直接使用gradle配置编译jni, 但原先项目从eclipse转移过来, 都配置了android.mk, 懒得重新配置, 网上找了下配置教程
//编译task
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
// def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
def ndkDir = android.ndkDirectory
println(" ========= ndkDir= $ndkDir")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir/ndk-build.cmd", '-C', file('jni').absolutePath, //项目的jni目录
"NDK_OUT=$buildDir/ndk/obj",
"NDK_APP_DST_DIR=$buildDir/ndk/libs/\$(TARGET_ARCH_ABI)"
} else {
commandLine "$ndkDir/ndk-build", '-C', file('jni').absolutePath,
"NDK_OUT=$buildDir/ndk/obj",
"NDK_APP_DST_DIR=$buildDir/ndk/libs/\$(TARGET_ARCH_ABI)"
}
}
task copyJniLibs(type: Copy, dependsOn: 'ndkBuild') {
from fileTree(dir: file(buildDir.absolutePath + '/ndk/libs'), include: '**/*.so')
printf("============ $buildDir/ndk/libs/")
into file('src/main/jniLibs')
}
//编译时 依赖
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn copyJniLibs
}
//clean jni
task cleanNdkBuild(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir/ndk-build.cmd", '-C', file('jni').absolutePath, 'clean'
} else {
commandLine "$ndkDir/ndk-build", '-C', file('jni').absolutePath, 'clean'
}
}
clean.dependsOn 'cleanNdkBuild'
指定module路径和名称
Android studio 默认是所有的module在同一个子目录下, 但有时因为各种原因, 依赖工程无法在统一目录, 可以在 setting.gradle中, 指定路径和名称
include ':videocomponent'
project(':videocomponent').projectDir = new File('../../libproject/videocomponent')