【发布时间】:2017-07-05 14:47:50
【问题描述】:
这是我的目录结构
src -main
-java
-jniLibs
-armeabi
-lib1.so
-lib2.so
需要了解应该在构建 gradle 文件中编写哪些代码才能将这些文件包含在构建中。 现在,我收到了找不到 .so 文件的错误。
java.lang.UnsatisfiedLinkError: nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libFPEComponent.so"
我必须在这里添加
我的 bUild.gradle 文件
apply plugin: 'com.android.application'
android {
productFlavors {
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
}
}
sourceSets
{
main
{
jniLibs.srcDirs = ['src/main/jnilibs']
}
//Another code
}
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.goambee.biometricziqitza"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86, armeabi-v7a, and mips.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "armeabi-v7a"
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}
//task native-libstiveLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
// destinationDir file("$buildDir/native-libs")
// baseName 'native-libs'
// from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
// into 'lib/'
//}
//
//tasks.withType(JavaCompile)
// {
// compileTask -> compileTask.dependsOn(nativeLibsToJar)
// }
这里我已经包含了源集块,我也测试过没有那个块。 所以仍然 build 无法访问 .so 文件。
【问题讨论】:
-
您是在尝试构建库还是想直接在您的应用中运行 .so 文件?
-
使用那些 .so 文件
-
如果你使用 .so 文件,你不必在 gradle 中做任何事情。你可以直接从文件夹中使用它
-
您是否使用 android NDK 构建 .so 文件?
-
好吧,我没有在 build.gradle 中编写任何代码,正如我展示的结构,那些 .so 文件在 src/main/jniLibs 中,但它不起作用,因为它失败并出现错误“无法找到 some.so 文件”。我该怎么办?
标签: android android-studio java-native-interface build.gradle .so