Skip to content

Example of calling Java methods through the JNI, in ARM Assembly, on Android

License

Notifications You must be signed in to change notification settings

Miouyouyou/ARMv7-Java-JNI-call

Repository files navigation

Pledgie ! Tip with Altcoins

About

This example demonstrates how to :

  • generate a library containing a procedure written in ARMv7 GNU ASsembly
  • call this procedure from a Android app using the JNI
  • call a Java method, defined in the Android app, from the Assembly procedure using the JNI

Building

Building using GNU Make

Requirements

  • GNU AS
  • Gold linker
  • An ARM Android phone/emulator on which you have installation privileges

Build

Run make from this folder

Manually

Run the following commands :

# cross compiler prefix. Remove if you're assembling from an ARM machine
export PREFIX="armv7a-hardfloat-linux-gnueabi"
export APP_DIR="./apk"
export LIBNAME="libarcane.so"
$PREFIX-as -o decypherArcane.o decypherArcane.s
$PREFIX-ld.gold -shared --dynamic-linker=/system/bin/linker -shared --hash-style=sysv -o $LIBNAME decypherArcane.o
mkdir -p $APP_DIR/app/src/main/jniLibs/armeabi{,-v7a}
cp $LIBNAME $APP_DIR/app/src/main/jniLibs/armeabi
cp $LIBNAME $APP_DIR/app/src/main/jniLibs/armeabi-v7a

Building using Android ndk-build

Requirements

  • The Android NDK path in your system's PATH directory

Build

  • On Windows, run 'mkbuild.bat'
  • On Linux, run 'mkbuild.sh'

Installing the prepared APK

  • Connect your ARMv7 Android phone/emulator
  • open a shell or a "command window"
  • cd to the apk folder

Then :

  • On Windows run gradlew installDebug.
  • On Linux run ./gradlew installDebug