这期内容当中小编将会给大家带来有关Android Studio 2.1.2 Ndk的开发步骤是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
必要修改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.7.0' //修改了
// 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, 名称随意起.
如果为cpp, 内容为:
#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!");
}
如果为c, 内容为:
#include "myself_exercise_myndktestt_Load.h"
JNIEXPORT jstring JNICALL Java_myself_exercise_myndktestt_Load_getCLanguageString
(JNIEnv * env, jobject)
{
return (*env)->NewStringUTF(env, "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();
上述就是小编为大家分享的Android Studio 2.1.2 Ndk的开发步骤是什么了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。