简体   繁体   English

你好世界jni使用ARM代码

[英]hello world jni using ARM code

I trying to use ARM code from Android, using JNI. 我试图使用JNI从Android使用ARM代码。 After i downloaded everything (NDK, toolchain) i opened the example NDK project called hello-jni. 下载完所有内容(NDK,工具链)后,我打开了一个名为hello-jni的示例NDK项目。 After build, it worked well. 构建后,它运行良好。 Now i try to use some ARM. 现在,我尝试使用一些ARM。 I found a hello-world ARM example: 我找到了一个世界末日的ARM示例:

.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: 我修改了C源代码,添加了一个功能:

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

i modified the Android.mk file too: 我也修改了Android.mk文件:

LOCAL_SRC_FILES := hello-jni.c multiple.S

After that i build the native code using ndk-build, i got an error: 之后,我使用ndk-build构建本机代码,但出现错误:

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? 我应该单独编译ARM代码吗? I thought, the ndk-build will build it. 我以为ndk-build将构建它。

--edit my application.mk file: -编辑我的application.mk文件:

APP_ABI := all

You are compiling for all architectures. 您正在为所有体系结构进行编译。 If you only want to compile for ARM, use APP_ABI := armeabi in your Application.mk file. 如果只想为ARM编译, APP_ABI := armeabi在Application.mk文件中使用APP_ABI := armeabi

Take a look at docs/APPLICATION-MK.html in your NDK installation for more information. 查看NDK安装中的docs/APPLICATION-MK.html了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM