2
votes

I trying to use ARM code from Android, using JNI. After i downloaded everything (NDK, toolchain) i opened the example NDK project called hello-jni. After build, it worked well. Now i try to use some ARM. I found a hello-world ARM example:

.align  2
.global armFunction
.type   armFunction, %function

armFunction:
    stmfd   sp!, {fp,ip,lr}
    mov r3, r0, asl #3
    add r0, r3, r0, asl #1
    ldmfd   sp!, {fp,ip,lr}
    bx  lr
    .size   armFunction, .-armFunction

I modified the C source code, added a function:

 jint
 Java_com_example_hellojni_HelloJni_factorialJNI(
 JNIEnv* env, jobject object, jint input) {
 return armFunction(input);
 }

i modified the Android.mk file too:

LOCAL_SRC_FILES := hello-jni.c multiple.S

After that i build the native code using ndk-build, i got an error:

c:\android\hello-jni\ndk-build
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [x86-4.6] libs/x86/gdbserver
Gdbsetup       : libs/x86/gdb.setup
Gdbserver      : [mipsel-linux-android-4.6] libs/mips/gdbserver
Gdbsetup       : libs/mips/gdb.setup
"Compile arm  : hello-jni <= hello-jni.c
"Compile arm  : hello-jni <= multiple.S
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => libs/armeabi-v7a/libhello-jni.so
"Compile arm  : hello-jni <= hello-jni.c
"Compile arm  : hello-jni <= multiple.S
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
"Compile x86  : hello-jni <= hello-jni.c
"Compile x86  : hello-jni <= multiple.S
jni/multiple.S: Assembler messages:
jni/multiple.S:6: Error: no such instruction: `stmfd sp!,{fp,ip,lr}'
jni/multiple.S:7: Error: too many memory references for `mov'
jni/multiple.S:8: Error: too many memory references for `add'
jni/multiple.S:9: Error: no such instruction: `ldmfd sp!,{fp,ip,lr}'
jni/multiple.S:10: Error: no such instruction: `bx lr'
make: *** [obj/local/x86/objs-debug/hello-jni/multiple.o] Error 1

Why those instructions are not working? Should i just compile the ARM code seperately? I thought, the ndk-build will build it.

--edit my application.mk file:

APP_ABI := all
1
why your build try to compile towards x86 platforms ? That may be the reason behind your bug : stmfd and ldtmfd are ARM instructions, not x86 ones. Does libs/armeabi-v7a/libhello-jni.so work ? - lucasg
i modified the post just that one line is in the application.mk, i'am very new to Android native things, so this is my first trying, i just tried a kind of hello-world-android-asm what i found on the internet. i'am on Windows 8 64bit, and i would like to build it to Android 4.3, i would try it on my phone not just on the emu (but first it's okay on emu) without using any ARM thing, the JNI itself works good - user1552747
if someone could give me a working ARM example what i can call from JNI under Android, it's also fine with me! what i would achive is to call ARM instructions from my Android phone - user1552747
Yeah, you're compiling for all architectures. If you only want arm, use APP_ABI := armeabi in your Application.mk - krsteeve
Actually it works! That was the problem, thanks a lot! Now i can see the factorial result from ARM Assembly, thought JNI on my Activity window. Maybe you should write it as an answer, than i can accept it. - user1552747

1 Answers

1
votes

You are compiling for all architectures. If you only want to compile for ARM, use APP_ABI := armeabi in your Application.mk file.

Take a look at docs/APPLICATION-MK.html in your NDK installation for more information.