标签:individual common files 开发 where
修改1:
build.gradle文件:
// 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.6.0-beta5‘ //修改了
// 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
}
修改2:
app\build.gradle文件:
apply plugin: ‘com.android.model.application‘ //修改了
model{
android {
compileSdkVersion 22
buildToolsVersion "24"
defaultConfig {
applicationId "myself.exercise.myndktest"
minSdkVersion.apiLevel 15 //修改了
targetSdkVersion.apiLevel 22//修改了
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
proguardFiles.add(file("proguard-rules.pro")) //修改了
}
}
ndk{
moduleName "lb" //增加的部分
}
}
}
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‘
}
步骤1:
右键app->src->main: New->Folder->JNI Folder 不用勾选CheckBox
步骤2:
右键app->src->main->java->myself.exercise.myndktestt: New->Java Class->填写Class名称,这里为Load
内容为
public class Load {
static {
System.loadLibrary("lb");
}
public native String getCLanguageString();
}
步骤3:
Build->Make Project
步骤4:
cd app\build\intermediates\classes\debug
javah -jni myself.exercise.myndktestt.Load //这里Load第一个字母为大写
发现app\build\intermediates\classes\debug目录下多出一个myself_exercise_myndktestt_Load.h
步骤5:
将myself_exercise_myndktestt_Load.h剪贴到app\src\main\jni目录下
在该jni目录右键 New->C/C++ Source File
内容为:
#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!");
}
步骤6:
在MainActivity.java中加入调用
Load ld = new Load();
Toast.makeText(getApplicationContext(), ld.getCLanguageString(), Toast.LENGTH_SHORT).show();
本文出自 “清澈” 博客,请务必保留此出处http://ggxxjj123.blog.51cto.com/1079641/1844504
标签:individual common files 开发 where
原文地址:http://ggxxjj123.blog.51cto.com/1079641/1844504