Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Android Studio 2.1.2 what are the development steps for Ndk

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the development steps of Android Studio 2.1.2 Ndk. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Necessary modification 1:

Build.gradle file:

/ / 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' / / 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

}

Necessary modifications 2:

App\ build.gradle file:

Apply plugin: 'com.android.model.application' / / modified

Model {/ / modified

Android {

CompileSdkVersion 22

BuildToolsVersion "24"

DefaultConfig {

ApplicationId "myself.exercise.myndktest"

MinSdkVersion.apiLevel 15 / / modified

TargetSdkVersion.apiLevel 22max / modified

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" / / additions

}

}

}

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'

}

-

Method 1:

Step 1:

Right-click app- > src- > main: New- > Folder- > JNI Folder do not check CheckBox

Step 2:

Right-click app- > src- > main- > java- > myself.exercise.myndktestt: New- > Java Class- > enter the Class name, here is Load

The 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 the first letter of Load is capitalized

Found an extra myself_exercise_myndktestt_Load.h in the app\ build\ intermediates\ classes\ debug directory

Step 5:

Cut and paste myself_exercise_myndktestt_Load.h to the app\ src\ main\ jni directory

Right-click New- > C jni + Source File in the directory, and name it at will.

If cpp, the content is:

# 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!")

}

If c, the content is:

# 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!")

}

Step 6:

Add a call to the MainActivity.java

Load ld = new Load ()

Toast.makeText (getApplicationContext (), ld.getCLanguageString (), Toast.LENGTH_SHORT) .show ()

These are the steps of the development of Android Studio 2.1.2 Ndk shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report