Android Studio GradleプロジェクトにJNI soファイルを追加


まずAndroid Studio(バージョン1.2.2)プロジェクトのappディレクトリの下にjniディレクトリ全体を作成し、jniディレクトリにAndroidと書きます.mk、Application.mkおよび各種C/C++とアセンブリソースファイル.そして元と同じようにndk_buildツールを編集すると、ツールは自動的にlibsディレクトリを生成します.中にはアプリケーションもあります.mkで指定したプロセッサアーキテクチャのsoファイル.
サードパーティsoを参照する場合は、関連するファイルをlibsディレクトリの下に直接配置します.
次にappディレクトリのbuildを編集します.gradleファイルで、次のコードを追加します.
 sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

完全なbuild.gradleファイルは次のようになります.
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.qianmi.myapp"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.mcxiaoke.volley:library:1.0.16'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.github.bumptech.glide:glide:3.6.0'
    compile 'com.jakewharton:butterknife:7.0.1'
}