【发布时间】:2018-05-18 13:11:48
【问题描述】:
为什么我的 Android Studio 没有找到相关的 JNI 类?
我在 AsyncTask 中有一个名为 opensslSign 的类,它与 jni .so 文件 libcryptowrapper.so 相关。构建工作正常,但 Android Studio 抱怨:“无法解析相应的 JNI 函数”。我已将我的 .so 文件移动到多个文件夹中,只是为了查看 Android 是否找到它,但没有运气。
This is a screenshot Android Studio 能够在.so 文件和jni 类目录中找到JNI 类(包含Android.mk)
我的摇篮:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.0.0'
compile fileTree(dir: 'libs', include: '*.so')
compile fileTree(dir: 'lib', include: '*.jar')
compile(name:'google-maps-sdk-m4b', ext:'aar')
compile(project(':deps:android-map-utils:library')) {
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.google.android.gms:play-services:11.0.4'
compile "com.google.android.gms:play-services-location:11.0.4"
compile group: 'org.apache.james', name: 'apache-mime4j', version: '0.6'
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'net.lingala.zip4j', name: 'zip4j', version: '1.3.2'
compile group: 'net.sf.kxml', name: 'kxml2', version: '2.3.0'
compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.3'
compile group: 'joda-time', name: 'joda-time', version: '2.9.5'
}
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
exclude 'build-data.properties'
}
defaultConfig {
// Already hit dex limit
multiDexEnabled true
dexOptions {
javaMaxHeapSize "4g"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
lintOptions {
abortOnError false
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
}
repositories {
flatDir{
dirs 'libs'
}
}
allprojects {
repositories {
jcenter()
}
}
【问题讨论】:
-
请阅读stackoverflow.com/a/44422873/192373,我希望这能回答你的问题
-
这是我一直在寻找的答案。谢谢。
标签: android android-studio android-ndk java-native-interface android-studio-3.0