One: Use Gradle experimental plugin
First of all, we can not use the Android studio default Gradle plugin, we need to change the Android Studio plugin Gradle Experimental plugin, this plugin is developed by Google, the URL here:
Http://tools.android.com/tech-docs/new-build-system/gradle-experimental
Gradle Experimental plugin is a new compiled plugin for Android studio that improves the compiler performance of the program. In addition, it supports the NDK, which compiles JNI applications. Currently (May 2016) The latest version is 0.7.0
II: Software Preparation:
- Gradle 2.10
- Android NDK r10e
- Android SDK Build Tools version 23.0.3
Three: Changes in the directory structure
The following red is required to modify the configuration, there are three main:
├──app/
│├──app.iml
│├── build.gradle----------> Module compilation configuration File
│└──src/
├── build.gradle ----------> Engineering Compilation configuration file
├──gradle/
│└──wrapper/
│├──gradle-wrapper.jar
│└── gradle-wrapper.properties ----------> Gradle version configuration file
├──gradle.properties
├──gradlew*
├──gradlew.bat
├──local.properties
├──myapplication.iml
└──settings.gradle
./gradle/wrapper/gradle-wrapper.properties :
#Wed Apr 15:27:10 PDT
Distributionbase=gradle_user_home
distributionpath=wrapper/dists
Zipstorebase=gradle_user_home
zipstorepath=wrapper/dists
distributionurl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
./build.gradle :
repositories {
jcenter ()
Span style= "font-family: ' Courier New '; letter-spacing:0;font-size:14px;" > }
dependencies {
//classpath ' com.android.tools.build:gradle:2.1.0 '
Classpath"Com.android.tools.build:gradle-experimental:0.7.0"
}
}
allprojects {
Repositories {
Jcenter ()
}
}
./app/build.gradle
Apply plugin: "Com.androi d. Model . A pplication "
Model {
Android {
Compilesdkversion 23
Buildtoolsversion "23.0.3"
NDK {
ModuleName "Hellojni"
Ldlibs.add ("log")//native code with Android Logcat log
}
Defaultconfig {
ApplicationID "Cn.itcast.testjni"
Minsdkversion.apilevel 19
Targetsdkversion.apilevel 22
Versioncode 1
Versionname "1.0"
}
}
}
dependencies {
Compile Filetree (dir: "Libs", include: ["*.jar"])
}
Reference Links:
Https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html
Android Studio NDK Development configuration