Compile Jni Code in Android Studio
Transcript of Compile Jni Code in Android Studio
-
7/26/2019 Compile Jni Code in Android Studio
1/3
Guide To Compile jni
code in Android Studio01 JUNE 2016/ 4:00 PM / Videocon R&D
Create Android Project Open Android Studio. Select Start new Android Studio Project. Set Application name. In this guide I will usejniCompile. Set Company name. In this guide I will use ord.d2h.ideocon . hit Ne!t
In the Select the "orm "actor# your app will run onI used Phone and $a%letandselected AP& '( Android 2.) *+in,er%read-but ou can t! othe! setups.
hit Ne!t. Select Empty Actiityand hit Ne!t. "ea#e Actiity Nameand all the othe! $elds as is and hit Ne!t.
Jni Folder1. In the Projectfile viewer find pathjniCompile / app / src2. On srcfolder do Right Click -> New -> DirectoryName itjniand hit OK.
3. Ifjnifolder already available put it under src.
C Library File
All the c files should be placed under jni folder.
Example of how to define methods in c
The function name Java_eu_ratikal_helloc_ainActivit!_"et#trin"is based
on this patternJava___.
* can be found in the fist line of projects ainActivit!.javafile.
* can also be found in ainActivit!.javafile and is the class
name! in this case MainActivity.
* you decide it" In this e#ample id getString.
-
7/26/2019 Compile Jni Code in Android Studio
2/3
2
Android.mk%.
. Insidejnifolder create a file named Android.mk$same procedure with %ello&.c'.'. (ndroid.m) is a the file that instructs nd)build how to compile and create the library
for java to call the &.
4. (dd the followin+ code in Android.mk
(. "#C$"_%$&' () *+call my-,ir
incl!,e *+C".$R_$R0
"#C$"_1#D2". () helloc
"#C$"_0RC_34".0 () 'elloC5c
incl!,e *+624"D_0'$R.D_"46R$R7
S)ip i* $le al!ead a#ailable
Application.mk
Insidejnifolder create a file named Application.mk$same procedure with %ello&.c and
(ndroid.m)'.
(pplication.m) is a the file that instructs nd)build how to compile and create the library for java to
call the &.
(dd the followin+ code in Application.mk
$%%_$64 () armea8i armea8i-v9a mips :;
$%%_%"$&3#R1 () an,roi,-=
,ou can s)ip creatin+ (pplication.m) if you now that armeabi is fine for your testdevice. If you dont understand this! create the file and probably you are +oin+ tobe o)"
Build the library
Now build the library"
-
7/26/2019 Compile Jni Code in Android Studio
3/3
)
In the terminal of (ndroid studio +ive the below command to +enerate the .so files
* c, app/src/jni
app/src/jni * path-to-n,k-,irectory/n,k-8!il,
Moe !le" to jniLib" #older
jni$ibsis the folder where function 0ystem5loa,"i8rary+55 searches for nativelibraries.
n,k-8!il,created folderjniCompile/app/src/li8s. -ename and move this folder tojniCompile/app/src/main/jni"i8s.
Load and Call the natie C #unction #rom jaa
+se 0ystem5loa,"i8rary+?name o 5so @le witho!t e:tensionA in a static bloc) to
i,po!t in a sepa!ate utilit class . -his class should decla!e the ,ethods o* lib with natieeyword
$hi# can %e done within actiity or any cla## %ut recommended to create a #eparate utility cla##
"or code cleanline##