带有本机库错误的 Android Studio Gradle [英] Android Studio Gradle with native libs error
问题描述
对不起我的英语...
我有最后一个 android studio(2013 年 6 月 14 日).创建新的 Android 项目.将 .so 文件添加到/libs/armeabi
I have last android studio (14 june 2013). Create new Android project. Add .so files to /libs/armeabi
将 build.gradle 编辑为
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')
}
我收到一个错误:FAILURE:构建失败,出现异常.
I received an error: FAILURE: Build failed with an exception.
- 出了什么问题:任务':JaCertTest:packageDebug'的配置发现问题.
- What went wrong:
A problem was found with the configuration of task ':JaCertTest:packageDebug'.
为属性jniDir"指定的目录build\native-libs"不存在.
Directory 'build\native-libs' specified for property 'jniDir' does not exist.
- What went wrong:
A problem was found with the configuration of task ':JaCertTest:packageDebug'.
推荐答案
如果您的 copyNativeLibs 任务未能找到任何文件,因此不会创建build\native-libs"目录,则会发生这种情况.你确定你的libs/armeabi"目录下有 .so 文件吗?
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?
另外,请记住,您的脚本实际上不会编译本机代码.您仍然需要自己通过运行 ndk-build 来生成 .so 库.
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.
以下是如何让脚本编译本机代码的示例.请注意,这要求 ndk-build 在您的 PATH 中.
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 Studio Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!