Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android編程入門 >> Android studio 配置JNI環境

Android studio 配置JNI環境

編輯:Android編程入門

Android studio配置jni開發環境,主要配置是兩個build文件,以及新建一個jni文件,放c代碼。

 

代碼如下1:

apply plugin: 'com.android.model.application'

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

        defaultConfig.with {
            applicationId = "me.chunsheng.jni"
            minSdkVersion.apiLevel = 9
            targetSdkVersion.apiLevel = 23
        }

    }


    /*
 * native build settings
 */
    android.ndk {
        moduleName = "hello-world"
        /*
    moduleName = "hello-jni"
     * 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
            multiDexEnabled = true
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }


    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("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 empty
        create("all")
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
}

 

代碼如下2:

 

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

 

直接編譯,運行即可調用c代碼了,本次Android studio版本 2.0—beta 7.以及配置文件如上。

 

 

由於版本更新,gradle的語法的改變,build文件可能會發生變化,時刻關注官網 

 

http://tools.android.com/tech-docs/new-build-system/gradle-experimental#TOC-0.2.x---0.4.0

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved