Revision 1:
Build.gradle file:
Top-level build file where can add configuration options common to all sub-projects/modules.
Buildscript {
repositories {
Jcenter ()
}
dependencies {
Classpath ' COM.ANDROID.TOOLS.BUILD:GRADLE-EXPERIMENTAL:0.6.0-BETA5 '//Modified
Note:do not place your application dependencies here; They belong
In the individual module Build.gradle files
}
}
allprojects {
repositories {
Jcenter ()
}
}
Task Clean (type:delete) {
Delete Rootproject.builddir
}
Revision 2:
App\build.gradle file:
Apply plugin: ' com.android.model.application '//Modified
model{
Android {
Compilesdkversion 22
Buildtoolsversion "24"
Defaultconfig {
ApplicationID "Myself.exercise.myndktest"
Minsdkversion.apilevel 15//Modified
Targetsdkversion.apilevel 22//modified the
Versioncode 1
Versionname "1.0"
}
Buildtypes {
Release {
Minifyenabled false
Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '
Proguardfiles.add (File ("Proguard-rules.pro"))//Modified
}
}
ndk{
ModuleName "lb"//Added part
}
}
}
dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
Testcompile ' junit:junit:4.12 '
Compile ' com.android.support:appcompat-v7:22.2.1 '
Compile ' com.android.support:design:22.2.1 '
}
Step 1:
Right-click App->src->main:new->folder->jni Folder without checking the checkbox
Step 2:
Right-App->src->main->java->myself.exercise.myndktestt:new->java class-> fill in the Class name, here is the load
Content is
public class Load {
static {
System.loadlibrary ("lb");
}
Public native String getclanguagestring ();
}
Step 3:
Build->make Project
Step 4:
CD App\build\intermediates\classes\debug
Javah-jni myself.exercise.myndktestt.Load//Here Load First letter is uppercase
Found an extra myself_exercise_myndktestt_load.h in the App\build\intermediates\classes\debug directory
Step 5:
Paste the myself_exercise_myndktestt_load.h into the App\src\main\jni directory
Right-new->c/c++ The Source File in the JNI directory
The contents are:
#include "Myself_exercise_myndktestt_load.h"
Jniexport jstring Jnicall java_myself_exercise_myndktestt_load_getclanguagestring
(JNIENV * env, Jobject)
{
Return Env->newstringutf ("This just a test for Android Studio NDK JNI developer!");
}
Step 6:
Add a call to the Mainactivity.java
Load ld = new Load ();
Toast.maketext (Getapplicationcontext (), ld.getclanguagestring (), Toast.length_short). Show ();
This article is from the "Clear" blog, please be sure to keep this source http://ggxxjj123.blog.51cto.com/1079641/1844504
Android2.1.2 NDK Development Steps