Android Studio Gradle项目中添加JNI so文件

      首先在Android Studio(版本1.2.2)工程的app目录下创建整个jni目录,jni目录里写Android.mk、Application.mk以及各类C/C++和汇编源文件。然后跟原来一样,用ndk_build工具去编,然后工具会自动生成libs目录,里面还有每个你在Application.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'
}


你可能感兴趣的:(jni,gradle,so)