NDK和项目依赖

NDK使用

  • JDK:Java Development Kit
  • SDK:Software Development Kit
  • NDK:Native Development Kit
  • JNI: Java Nattive Interface

NDK开发流程:

  • 下载NDK并配置NDK路径
  • 新建项目
  • 修改build.gradle文件

    替换classpath:com.android.tools.build:gradle-experimental:0.4.0

    替换apply plugin:com.android.model.application

    添加moudel{}至android{},即:model{android{}}minSdkverion 15 targetSdkVersion 23

      versionCode 1versionName "1.o"
      替换为
      minSdkVersion.apiLevel=4
      targetSdkVersion.apilevel=23
  • 添加android.ndk{moduleName="onlystar-android-jni-demo"}
  • 参考实例Demo的build.gradle
apply plugin: 'com.android.model.application'

    model {
    android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.2"

    defaultConfig.with {
    applicationId = "com.example.hellojni"
    minSdkVersion.apiLevel = 15
    targetSdkVersion.apiLevel = 23
    }
    }

    compileOptions.with {
    sourceCompatibility=JavaVersion.VERSION_1_7
    targetCompatibility=JavaVersion.VERSION_1_7
    }

/*
 * native build settings
 */
    android.ndk {
    moduleName = "geekband-hello-jni-demo"/*
     * Other ndk flags configurable here are
     * cppFlags.add("-fno-rtti")
     * cppFlags.add("-fno-exceptions")
     * ldLibs.addAll(["android", "log"])
     * stl       = "system"
     */
    }
    android.buildTypes {
    release {
    minifyEnabled = false
    proguardFiles.add(file('proguard-rules.txt'))
    }
    }
    android.productFlavors {
    // for detailed abiFilter descriptions, refer to "Supported ABIs" @ // https://developer.android.com/ndk/guides/abis.html#sacreate("arm") {
    ndk.abiFilters.add("armeabi")
    }
    create("arm7") {
    ndk.abiFilters.add("armeabi-v7a")
    }
    create("arm8") {
    ndk.abiFilters.add("arm64-v8a")
    }
    create("x86") {
    ndk.abiFilters.add("x86")
    }
    create("x86-64") {
    ndk.abiFilters.add("x86_64")
    }
    create("mips") {
    ndk.abiFilters.add("mips")
    }
    create("mips-64") {
    ndk.abiFilters.add("mips64")
    }
    // To include all cpu architectures, leaves abiFilters emptycreate("all")
    }
    }
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    }

项目依赖

引入aar文件----两种方法
1.在build.gradle中添加
allprogects{
    responsitores{
        jcenter()
        flatDir{
            dirs  'libs'
       }
   }
}
 在dependencies中添加
     compile(name:'aar_filename',ext:'aar')
2.新建module,选择 Import .JAR/.AAR Package,导入aar文件





posted @ 2015-08-08 12:11  星空守候  阅读(872)  评论(0编辑  收藏