How do I use JNI with AAR library?

柔情痞子 提交于 2019-12-04 04:08:20

Turns out I had to add some NDK config in my build.gradle file inside my AAR module directory.

build.gradle:

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        // This determines the .so filename
        ndk {
            moduleName "hello-jni"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Not having that added in build.gradle will produce an .so file that's defaulted to your project's name, in my case "libsample-aar.so". With that config above, the generated .so file will then be "libhello-jni.so".

You must build the native code with the command ndk-build from Android NDK.

This proccess will generate the linhello-jni.so that will be included in your build.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!