Android Studio抱怨缺少JNI类

时间:2018-05-18 13:11:49

标签: android android-studio android-ndk java-native-interface android-studio-3.0

为什么我的Android Studio找不到相关的JNI类?

我在名为opensslSign的AsyncTask中有一个类,它与jni .so文件libcryptowrapper.so相关。构建工作正常但Android Studio抱怨:“无法解析相应的JNI函数”。我已将.so文件移到多个文件夹中,只是为了查看Android是否找到了它,但没有运气。

This is a screenshot Android Studio能够在.so文件和jni类目录中找到JNI类(包含Android.mk

我的Gradle:

// 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()
    }
}

1 个答案:

答案 0 :(得分:0)

删除

拆分{         abi {             启用真实             重启()             包括&#39; x86&#39;,&#39; armeabi-v7a&#39;             universalApk是的         }     }

现在由Android工作室进行自动管理。