android gradle 配置

修改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')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值