码迷,mamicode.com
首页 > 移动开发 > 详细

Android2.1.2 Ndk开发步骤

时间:2016-08-30 22:52:56      阅读:202      评论:0      收藏:0      [点我收藏+]

标签: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

Android2.1.2 Ndk开发步骤

标签:individual   common   files   开发   where   

原文地址:http://ggxxjj123.blog.51cto.com/1079641/1844504

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!