Android的工作室摇篮与本机库错误 [英] Android Studio Gradle with native libs error

查看:138
本文介绍了Android的工作室摇篮与本机库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语...

我还有最后机器人工作室(2013年6月14日)。
创建新的Andr​​oid项目。
加入.so文件到/库/ armeabi

编辑的build.gradle到

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径'com.android.tools.build:gradle:0.4
    }
}
应用插件:'机器人'依赖{
    编译文件(库/ Android的支持 - v4.jar','库/ jcPKCS11.jar')
}安卓{
    compileSdkVersion 17
    buildToolsVersion17.0.0    defaultConfig {
        14的minSdkVersion
        targetSdkVersion 16
    }
}任务copyNativeLibs(类型:复制){
    从(新文件(项目(':JaCertTest。)getProjectDir(),库/ armeabi')){包括** / *左右。'}
    进入新的文件(buildDir,原生库)
}tasks.withType(编译){compileTask - > compileTask.dependsOn copyNativeLibs}clean.dependsOncleanCopyNativeLibstasks.withType(com.android.build.gradle.tasks.PackageApplication){pkgTask - >
    pkgTask.jniDir新的文件(构建/本机库)
}

我收到一个错误:
故障:建立失败,一个异常


  • 出了什么问题:
    一个问题是发现任务的配置。':JaCertTest:packageDebug


      

    目录构建\\本机库'财产'jniDir不存在指定。


  •   

  它是如何正确编写一个构建脚本?



解决方案

这将您的copyNativeLibs任务未能找到任何文件,因此不会产生打造\\本机库目录发生。你肯定有你的库/ armeabi目录.so文件?

另外,请记住,你的脚本将不实际编译本土code。你仍然需要自己做运行NDK的构建产生的.so库。

下面是如何让你的脚本来编译你的本地code的例子。请注意,这需要NDK的构建是在路径中。

  //任务运行NDK的构建
任务ndkBuild(类型:执行){
    命令行'NDK的构建,-j,Runtime.runtime.availableProcessors()
}任务copyNativeLibs(类型:复制){
    从(新文件(项目(':JaCertTest。)getProjectDir(),库/ armeabi')){包括** / *左右。'}
    进入新的文件(buildDir,原生库)
}//使copyNativeLibs取决于ndkBuild,因为我们必须构建库
//才可以复制。
copyNativeLibs.dependsOnndkBuild
tasks.withType(编译){compileTask - > compileTask.dependsOn copyNativeLibs}clean.dependsOncleanCopyNativeLibstasks.withType(com.android.build.gradle.tasks.PackageApplication){pkgTask - >
    pkgTask.jniDir新的文件(构建/本机库)
}

Sorry for my english...

I have last android studio (14 june 2013). Create new Android project. Add .so files to /libs/armeabi

Edit build.gradle to

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar','libs/jcPKCS11.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 16
    }
}

task copyNativeLibs(type: Copy) {
    from(new File(project(':JaCertTest').getProjectDir(), 'libs/armeabi'))  { include '**/*.so' }
    into new File(buildDir, 'native-libs')
}

tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }

clean.dependsOn 'cleanCopyNativeLibs'

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniDir new File('build/native-libs')
}

I received an error: FAILURE: Build failed with an exception.

  • What went wrong: A problem was found with the configuration of task ':JaCertTest:packageDebug'.

    Directory 'build\native-libs' specified for property 'jniDir' does not exist.

How it is correct to write an build script?

解决方案

This will happen if your copyNativeLibs task fails to find any files, and therefore doesn't create the "build\native-libs" directory. Are you sure that there are .so files in your "libs/armeabi" directory?

Also, keep in mind that your script won't actually compile the native code. You still need to do that yourself by running ndk-build to generate the .so libraries.

Here is an example of how to get your script to compile your native code. Note, this requires that ndk-build is in your PATH.

// Task to run ndk-build
task ndkBuild(type: Exec) {
    commandLine 'ndk-build', '-j', Runtime.runtime.availableProcessors()
}

task copyNativeLibs(type: Copy) {
    from(new File(project(':JaCertTest').getProjectDir(), 'libs/armeabi'))  { include '**/*.so' }
    into new File(buildDir, 'native-libs')
}

// Make copyNativeLibs depend on ndkBuild since we must build the libraries
// before we can copy them.
copyNativeLibs.dependsOn 'ndkBuild'
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }

clean.dependsOn 'cleanCopyNativeLibs'

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniDir new File('build/native-libs')
}

这篇关于Android的工作室摇篮与本机库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆