Android Studio 引用.so文件

将要引用的.so文件拷贝到src/main/jniLibs文件夹下

![Uploading image_553257.png . . .]

然后修改Build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "com.lisxhs.kuaiyue"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

//配置.so文件的引用
    sourceSets {
        main {
            //jniLibs.srcDirs = ['src/main/jniLibs']
            jniLibs.srcDirs = ['libs']  //将so文件路径(jniLibs)指向"libs"路径,这样就可以把so文件打包到APK的lib文件夹中
            //aidl.srcDirs = ['src/main/aidl']
        }


        task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
            destinationDir file("$buildDir/native-libs")
            baseName 'native-libs'
            extension 'jar'
            from fileTree(dir: 'libs', include: '**/*.so')
            into 'lib/'
        }

        tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn(nativeLibsToJar)
        }
    }
}

然后点击Build->Make Module,然后将项目选择为Android,查看.so是否被编译了。

你可能感兴趣的:(Android Studio 引用.so文件)