Android 存档

用Eclipse开发与调试纯粹的Android C++程序,非ndk-build、ndk-gdb

2011 年 09 月 01 日 分类目录 :Android 2

本文欢迎转载,但请注明出处,否则依法追究。源文链接: http://www.gqweb.net/eclipse-dev-an…-build-ndk-gdb_253.html

在做Android本地程序开发时,Google为我们提供了NDK开发环境,如果只是很小的工程,用NDK开发还是很方便的。但是如果是很大的工程,代码文件很多的时候,手工支配置android.mk文件还是很繁锁的。虽然Google不建议我们用NDK开发大规模的工程,但是在很多时候,例如,现有游戏或者其它工程的移植时,还是不可避免的。本文将介绍一种利用eclipse进行传统C++开发的方法。

一、  开发篇

1. 创建工程
打开eclipse新建C++工程–>键入工程名并选择Hello World C++ Project–>Finish

创建C++工程

选择Hello World工程

2.  设置工程属性
右键工程–>选择属性–>C/C++Build–>Tool Chain Editor : [Current toolchain: “Cross GCC”]

选择工具链

注意:如果没有所需的工具链选择,可能是eclipse的版本不对。

3. 设置工具链属性
右键工程–>选择属性–>C/C++Build–>Settings

工具链设置

3.1. [Cross Settings]

view source print ?
Prefex : arm-linux-androideabi-
Path : /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/

注意:

view source print ?
1. Path是指工具链的根目录,并不是可执行文件的目录,所以不需要加上 “/bin”目录。
2. /home/q/Workspace/Andriod/NDK/是NDK的根目录,请根据自己的情况选择。以下设置相同。

3.2. [Cross GCC Compiler]

view source print ?
Include Paths :
 /home/q/Workspace/Andriod/NDK/platforms/android-9/arch-arm/usr/include
 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/include
 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/include
 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/include
 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/include-fixed/
 /home/q/Workspace/Andriod/NDK/sources/cxx-stl/stlport/stlport/
Miscellaneous:
 Other Flags :-c -fmessage-length=0 -DANDROID -fno-exceptions

如果使用stlport,“-DANDROID -fno-exceptions” 选项是必须的否则 stlport中的 #include_next 没法使用,会报如下错误:

view source print ?
/home/q/Workspace/Andriod/NDK/sources/cxx-stl/stlport/stlport/stl/_cstddef.h:29:30: error: cstddef: No such file or directory

钩选:-fPIC

3.3. [Cross G++ Compiler] 同 3.2。

3.4. [Cross G++ Linker]
General: -nostdlib
Libraries:
添加的库:

view source print ?
1 c
2 m
3 stdc++
4 stlport

库路径:

view source print ?
1 /home/q/Workspace/Andriod/NDK/platforms/android-9/arch-arm/usr/lib
2 /home/q/Downloads/android_bak/NDK/sources/cxx-stl/stlport/libs/armeabi-v7a

Libraries设置

注意:
在/home/q/Downloads/android_bak/NDK/sources/cxx-stl/stlport/libs/armeabi-v7a路径下是没有libstlport.so文件的。我们需要从我们自己的设备上把此文件下载下来:

view source print ?
adb shell pull /system/lib/libstlport.so /home/q/Downloads/android_bak/NDK/sources/cxx-stl/stlport/libs/armeabi-v7a

Miscellaneous:
其它选项:
-R/home/q/Workspace/Andriod/NDK/platforms/android-9/arch-arm/usr/lib
其它对象:
/home/q/Workspace/Andriod/NDK/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o
/home/q/Workspace/Andriod/NDK/platforms/android-9/arch-arm/usr/lib/crtend_android.o

链接器选项

这样开发的配置就已经完成了,编译一下试试看吧!

view source print ?
1 adb push ./HelloWorld /data/td/
2 adb shell /data/td/HelloWorld

注意:如果将程序放到sdcard上是不能执行的,即使已经root了,chmod也设置不了权限的。
二、 调试篇

虽然在NDK里面有ndk-gdb的工具使我们可以调试ndk-build编译出来的程序,但是它需要android.mk文件,从上一篇的介绍中我们并没有生成此文件。还有其它方法可以用吗?分析ndk-gdb文件我们提取出下面这些有用信息。

首先我们以命令行的方式来模拟ndk-gdb的操作:

1. 在设备上启动gdbserver监听gdb的请求:

view source print ?
1 root@g:~# adb devices
2 List of devices attached
3 353046FDC1EE00EC        device
4   
5 root@g:~# adb push /home/q/Workspace/cmu_test_remote/HelloWorld/Debug/HelloWorld  /data/td/
6 1002 KB/s (136536 bytes in 0.132s)
7 root@g:~# adb push /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver /system/xbin/
8 893 KB/s (125208 bytes in 0.136s)
9 root@g:~# adb shell gdbserver :5039 /data/td/HelloWorld
10 Process /data/td/HelloWorld created; pid = 21867
11 Listening on port 5039

2. 进行端口重定向:

view source print ?
1 adb forward tcp:5039 tcp:5039

因为gdb需要通过TCP或者串口进行连接,但大多数情况下我们是用USB线进行连接的,所以需要进行端口重定向。

3. Gdb 打开程序,进行调试:

view source print ?
1 root@g:~# /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb /home/q/Workspace/cmu_test_remote/HelloWorld/Debug/HelloWorld
2 GNU gdb 6.6
3 Copyright (C) 2006 Free Software Foundation, Inc.
4 GDB is free software, covered by the GNU General Public License, and you are
5 welcome to change it and/or distribute copies of it under certain conditions.
6 Type "show copying" to see the conditions.
7 There is absolutely no warranty for GDB.  Type "show warranty" for details.
8 This GDB was configured as "--host=x86_64-linux-gnu --target=arm-elf-linux"...
9 (gdb)

这里的gdb的版本一定要正确。这时已经进入了gdb调试模式,还需要进行与远程的gdbserver进行连接,在gdb模式下输入:

view source print ?
1 (gdb) target remote :5039
2 Remote debugging using :5039
3 warning: Unable to find dynamic linker breakpoint function.
4 GDB will be unable to debug shared library initializers
5 and track explicitly loaded dynamic code.
6 0xb0001000 in ?? ()
7 (gdb) l
8 4       // Version     :
9 5       // Copyright   : Your copyright notice
10 6       // Description : Hello World in C++, Ansi-style
11 7       //============================================================================
12 8
13 9       #include <iostream>
14 10      using namespace std;
15 11
16 12      int main() {
17 13              cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
18 (gdb) b main
19 Breakpoint 1 at 0x84e8: file ../src/HelloWorld.cpp, line 13.
20 (gdb) c
21 Continuing.
22 Error while mapping shared library sections:
23 /system/bin/linker: No such file or directory.
24 Error while mapping shared library sections:
25 libc.so: Success.
26 Error while mapping shared library sections:
27 libm.so: Success.
28 Error while mapping shared library sections:
29 libstdc++.so: Success.
30 Error while mapping shared library sections:
31 libstlport.so: Success.
32   
33 Breakpoint 1, main () at ../src/HelloWorld.cpp:13
34 13              cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
35 (gdb) c
36 Continuing.
37   
38 Program exited normally.
39 (gdb)

至此已经完成了整个程序的调试过程。

4.  与Eclipse集成

虽然通过命令行已经可以对程序进行调试,但毕竟没有图形界面的方便,下面将介绍如何将gdb调试与Eclipse进行集成。

4.1. 到Eclipse中选中需调试的工程 ,打开Debug Configurations…

打开Debug Configurations

4.2. 在打开的Debug Configurations中新建C/C++ Remote Application

在main页面中设置:
Connection: local
Remote Absolute File Path : /data/td/HelloWorld
Commands to execute before application:

view source print ?
/home/q/Workspace/Andriod/SDK/platform-tools/adb shell gdbserver :5039 /data/td/HelloWorld
/home/q/Workspace/Andriod/SDK/platform-tools/adb forward tcp:5039 tcp:5039

注意,这里的adb路径一定要完整路径。最后还要选中 “Skip download to target path”

HelloWorld Debug设置

转到Debugger页片,填入gdb的完整路径,并将GDB command file置空。

Debug gdb路径设置

至此配置工作全部结束,直接点击调试吧。

参考:

1. Android Native Development Using the Android Open Source Project[OL]. http://www.aton.com/android-native-development-using-the-android-open-source-project/
2. Debugging with GDB[OL].  http://www.kandroid.org/online-pdk/guide/debugging_gdb.html
3. GDB 命令详细解释 [OL]. http://blog.csdn.net/wei801004/article/details/4253911
4. How C/C++ Debugging Works on Android[OL]. http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/
5. ndk-gdb[OL]. http://csipsimple.googlecode.com/svn/trunk/pjsip_android/ndk-gdb

android, Eclipse, native code, ndk

显示 Android NDK 编译和链接详情的方法

2011 年 08 月 27 日 分类目录 :Android 2

显示Android NDK  编译和链接详情有两种方法:

方法一:

如果有source,可以用source的mmm工具编译:

view source print ?
1 q@g:~$ cd /home/q/Workspace/Andriod/source/
2 q@g:~/Workspace/Andriod/source$ source build/envsetup.sh
3 including device/htc/passion/vendorsetup.sh
4 including device/samsung/crespo4g/vendorsetup.sh
5 including device/samsung/crespo/vendorsetup.sh
6 including sdk/bash_completion/adb.bash
7   
8 q@g:~/Workspace/Andriod/source$ help
9 Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
10 - croot:   Changes directory to the top of the tree.
11 - m:       Makes from the top of the tree.
12 - mm:      Builds all of the modules in the current directory.
13 - mmm:     Builds all of the modules in the supplied directories.
14 - cgrep:   Greps on all local C/C++ files.
15 - jgrep:   Greps on all local Java files.
16 - resgrep: Greps on all local res/*.xml files.
17 - godir:   Go to the directory containing a file.
18   
19 Look at the source to view more functions. The complete list is:
20 addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump
21   
22 q@g:~/Workspace/Andriod/source$ mmm /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni showcommands
23 ============================================
24 PLATFORM_VERSION_CODENAME=AOSP
25 PLATFORM_VERSION=3.1.4.1.5.9.2.6.5
26 TARGET_PRODUCT=full
27 TARGET_BUILD_VARIANT=eng
28 TARGET_SIMULATOR=
29 TARGET_BUILD_TYPE=release
30 TARGET_BUILD_APPS=
31 TARGET_ARCH=arm
32 TARGET_ARCH_VARIANT=armv7-a
33 HOST_ARCH=x86
34 HOST_OS=linux
35 HOST_BUILD_TYPE=release
36 BUILD_ID=OPENMASTER
37 ============================================
38 make:进入目录'/home/q/Workspace/Andriod/source'
39 build/core/base_rules.mk:78: *** Module name: hello-jni
40 build/core/base_rules.mk:79: *** Makefile location: /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni
41 build/core/base_rules.mk:80: *
42 build/core/base_rules.mk:81: * Each module must use a LOCAL_MODULE_TAGS in its
43 build/core/base_rules.mk:82: * Android.mk. Possible tags declared by a module:
44 build/core/base_rules.mk:83: *
45 build/core/base_rules.mk:84: *     optional, debug, eng, tests, samples
46 build/core/base_rules.mk:85: *
47 build/core/base_rules.mk:86: * If the module is expected to be in all builds
48 build/core/base_rules.mk:87: * of a product, then it should use the
49 build/core/base_rules.mk:88: * "optional" tag:
50 build/core/base_rules.mk:89: *
51 build/core/base_rules.mk:90: *    Add "LOCAL_MODULE_TAGS := optional" in the
52 build/core/base_rules.mk:91: *    Android.mk for the affected module, and add
53 build/core/base_rules.mk:92: *    the LOCAL_MODULE value for that component
54 build/core/base_rules.mk:93: *    into the PRODUCT_PACKAGES section of product
55 build/core/base_rules.mk:94: *    makefile(s) where it's necessary, if
56 build/core/base_rules.mk:95: *    appropriate.
57 build/core/base_rules.mk:96: *
58 build/core/base_rules.mk:97: * If the component should be in EVERY build of ALL
59 build/core/base_rules.mk:98: * products, then add its LOCAL_MODULE value to the
60 build/core/base_rules.mk:99: * PRODUCT_PACKAGES section of
61 build/core/base_rules.mk:100: * build/target/product/core.mk
62 build/core/base_rules.mk:101: *
63 build/core/base_rules.mk:102: *** user tag detected on new module - user tags are only supported on legacy modules。 停止。
64 make:离开目录“/home/q/Workspace/Andriod/source
65   
66 q@g:~/Workspace/Andriod/source$ mmm /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni showcommands
67 ============================================
68 PLATFORM_VERSION_CODENAME=AOSP
69 PLATFORM_VERSION=3.1.4.1.5.9.2.6.5
70 TARGET_PRODUCT=full
71 TARGET_BUILD_VARIANT=eng
72 TARGET_SIMULATOR=
73 TARGET_BUILD_TYPE=release
74 TARGET_BUILD_APPS=
75 TARGET_ARCH=arm
76 TARGET_ARCH_VARIANT=armv7-a
77 HOST_ARCH=x86
78 HOST_OS=linux
79 HOST_BUILD_TYPE=release
80 BUILD_ID=OPENMASTER
81 ============================================
82 make:进入目录'/home/q/Workspace/Andriod/source'
83 target thumb C: hello-jni <= /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni/hello-jni.c
84 prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc  -I /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni   -I out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates   -I dalvik/libnativehelper/include/nativehelper   -I system/core/include   -I hardware/libhardware/include   -I hardware/libhardware_legacy/include   -I hardware/ril/include   -I dalvik/libnativehelper/include   -I frameworks/base/include   -I frameworks/base/opengl/include   -I frameworks/base/native/include   -I external/skia/include   -I out/target/product/generic/obj/include   -I bionic/libc/arch-arm/include   -I bionic/libc/include   -I bionic/libstdc++/include   -I bionic/libc/kernel/common   -I bionic/libc/kernel/arch-arm   -I bionic/libm/include   -I bionic/libm/include/arch/arm   -I bionic/libthread_db/include  -c  -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funwind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security -fno-short-enums -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -include system/core/include/arch/linux-arm/AndroidConfig.h -I system/core/include/arch/linux-arm/ -Wno-psabi -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64       -MD -o out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates/hello-jni.o /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni/hello-jni.c
85 target SharedLib: hello-jni (out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates/LINKED/hello-jni.so)
86 prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-g++ -nostdlib -Wl,-soname,hello-jni.so -Wl,-T,build/core/armelf.xsc -Wl,--gc-sections -Wl,-shared,-Bsymbolic -Lout/target/product/generic/obj/lib         out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates/hello-jni.o       out/target/product/generic/obj/lib/crtbegin_so.o -Wl,--whole-archive   -Wl,--no-whole-archive   -lc -lstdc++ -lm  -o out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates/LINKED/hello-jni.so  -Wl,-z,noexecstack -Wl,--fix-cortex-a8   -Wl,--no-undefined  prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/libgcc.a out/target/product/generic/obj/lib/crtend_so.o
87 target Prelink: hello-jni (out/target/product/generic/symbols/system/lib/hello-jni.so)
88 out/host/linux-x86/bin/apriori --prelinkmap build/core/prelink-linux-arm.map --locals-only --quiet out/target/product/generic/obj/SHARED_LIBRARIES/hello-jni_intermediates/LINKED/hello-jni.so --output out/target/product/generic/symbols/system/lib/hello-jni.so
89 build/tools/apriori/prelinkmap.c(168): library 'hello-jni.so' not in prelink map
90 make: *** [out/target/product/generic/symbols/system/lib/hello-jni.so] 错误 1
91 make:离开目录“/home/q/Workspace/Andriod/source

方法二

直接用NDK的 ndk-build,不过需要加上参数 -B V=1

view source print ?
1 q@g:~/Workspace/Andriod/source$ ndk-build -B V=1 -C/home/q/Workspace/Andriod/NDK/samples/hello-jni/jni/
2 make:进入目录'/home/q/Workspace/Andriod/NDK/samples/hello-jni/jni'
3 rm -f /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/lib*.so /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi-v7a/lib*.so /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/x86/lib*.so
4 rm -f /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/gdbserver /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi-v7a/gdbserver /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/x86/gdbserver
5 rm -f /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/gdb.setup /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi-v7a/gdb.setup /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/x86/gdb.setup
6 Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
7 mkdir -p /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi
8 install -p /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/gdbserver
9 Gdbsetup       : libs/armeabi/gdb.setup
10 mkdir -p /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi
11 echo "set solib-search-path /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi" > /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/gdb.setup
12 echo "directory /home/q/Workspace/Andriod/NDK/platforms/android-8/arch-arm/usr/include /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni /home/q/Workspace/Andriod/NDK/sources/cxx-stl/system" >> /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/gdb.setup
13 Compile thumb  : hello-jni <= hello-jni.c
14 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -MMD -MP -MF /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o.d.org -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I/home/q/Workspace/Andriod/NDK/samples/hello-jni/jni -DANDROID  -Wa,--noexecstack -O0 -g -I/home/q/Workspace/Andriod/NDK/platforms/android-8/arch-arm/usr/include -c  /home/q/Workspace/Andriod/NDK/samples/hello-jni/jni/hello-jni.c -o /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o && ( if [ -f "/home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o.d.org" ]; then rm -f /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o.d && mv /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o.d.org /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o.d; fi )
15 SharedLibrary  : libhello-jni.so
16 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libhello-jni.so -shared --sysroot=/home/q/Workspace/Andriod/NDK/platforms/android-8/arch-arm  /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hello-jni.o        -Wl,--no-undefined -Wl,-z,noexecstack  -lc -lm -lsupc++ -o /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/libhello-jni.so
17 Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
18 mkdir -p /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi
19 install -p /home/q/Workspace/Andriod/NDK/samples/hello-jni/obj/local/armeabi/libhello-jni.so /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/libhello-jni.so
20 /home/q/Workspace/Andriod/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  /home/q/Workspace/Andriod/NDK/samples/hello-jni/libs/armeabi/libhello-jni.so
21 make:离开目录“/home/q/Workspace/Andriod/NDK/samples/hello-jni/jni”

Debug NDK by Eclipse

2011 年 08 月 11 日 分类目录 :Android 2

MartinH 已经在他的博客里面介绍的很详细,这里不再缀述,请参考:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/

http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/

error: .repo/manifests/: contains uncommitted changes 解决方法

2011 年 08 月 10 日 分类目录 :Android 2

今天在同步Android Source时出现

1 error: .repo/manifests/: contains uncommitted changes

google查找一阵子,无果,虽然也有人遇到但却没有给出解决方法。最后试了一下以下方法,得以解决。

  1. 删除Andriod/source/.repo/目录下除了projects目录以外的所有目录。
  2. 重新执行命令
1 repo init -u git://android.git.kernel.org/platform/manifest.git
2 repo sync

此时因为projects目录文件没有删除,所以重新同步不会重新下载所有文件,所以不会花费很长时间。

android

Android ndk 编译方法

2011 年 08 月 10 日 分类目录 :Android 1

1. 用NDK命令编译:

cd $(ndk-root)
./ndk-build -C/home/q/Workspace/Andriod/NDK/samples/test-libstdc++/jni

其中“-C”是指定需要编译的路径,其中必须有Android.mk。注意“-C”与路径之间没有空格。

详细使用方法请参见:

1 q@g:~/Workspace/Andriod/NDK$ ./ndk-build --help
2 用法:make [选项] [目标] ...
3 选项:
4   -b, -m                      忽略兼容性。
5   -B, --always-make           Unconditionally make all targets.
6   -C 目录, --directory=目录
7                               在所有操作前切换到“目录”。
8   -d                          打印大量调试信息。
9   --debug[=FLAGS]             打印各种调试信息
10   -e, --environment-overrides
11                               指定替代makefile中默认设置的环境变量
12   -f FILE, --file=FILE, --makefile=FILE
13                               读取 FILE 作为一个 makefile.
14   -h, --help                  打印该消息并退出。
15   -i, --ignore-errors         Ignore errors from commands.
16   -I DIRECTORY, --include-dir=DIRECTORY
17                               搜索 DIRECTORY 为包含的 makefiles.
18   -j [N], --jobs[=N]          同时允许 N 个任务;无参数表明允许无限个任务。
19   -k, --keep-going            当某些目标无法创建时仍然继续。
20   -l [N], --load-average[=N], --max-load[=N]
21                               不开始多线程工作除非系统负载低于N
22   -L, --check-symlink-times   Use the latest mtime between symlinks and target.
23   -n, --just-print, --dry-run, --recon
24                               不要实际运行任何命令;仅仅输出他们
25   -o FILE, --old-file=FILE, --assume-old=FILE
26                               FILE认作非常老,不要重新make它.
27   -p, --print-data-base       打印 make 的内部数据库。
28   -q, --question               不运行任何命令;退出状态说明是否已全部更新。
29   -r, --no-builtin-rules      禁用内置隐含规则。
30   -R, --no-builtin-variables   禁用内置变量设置。
31   -s, --silent, --quiet       不显示命令。
32   -S, --no-keep-going, --stop
33                               关闭 -k.
34   -t, --touch                 touch 目标而不是重新创建它们
35   -v, --version               打印 make 的版本号并退出。
36   -w, --print-directory       打印当前目录。
37   --no-print-directory        即使 -w 隐式开启,也要关闭 -w。
38   -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
39                               FILE认作无限新.
40   --warn-undefined-variables  Warn when an undefined variable is referenced.
41   
42 这个程序创建为 x86_64-pc-linux-gnu
43 Report bugs to

2. 使用源码自带Toolchain工具

如果你已经得到了Android源码,你还可通过Android源码中提供的Make工具编译,这种方法的好处是可以查看更多的编译细节。

1.  初始化,使用命令

1 $ source build/envsetup.sh

或者

1 $ . build/envsetup.sh

2. 直接输入命令,可以查看编译的命令

1 q@g:~/Workspace/Andriod/source$ help
2 Invoke ". build/envsetup.sh" from your shell to add the following functions
3 to your environment:
4 - croot:   Changes directory to the top of the tree.
5 - m:       Makes from the top of the tree.
6 - mm:      Builds all of the modules in the current directory.
7 - mmm:     Builds all of the modules in the supplied directories.
8 - cgrep:   Greps on all local C/C++ files.
9 - jgrep:   Greps on all local Java files.
10 - resgrep: Greps on all local res/*.xml files.
11 - godir:   Go to the directory containing a file.
12   
13 Look at the source to view more functions. The complete list is:
14 add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct
15 choosetype choosevariant cproj croot findmakefile gdbclient
16 get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help
17 isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu
18 resgrep runhat runtest set_java_home setpaths set_sequence_number
19 set_stuff_for_environment settitle smoketest startviewserver stopviewserver
20 systemstack tapas tracedmdump

3. 使用mmm命令编译NDK下面的例子

1 q@g:~/Workspace/Andriod/source$ mmm /home/q/Workspace/Andriod/NDK/samples/test-libstdc++/jni/
2 ============================================
3 PLATFORM_VERSION_CODENAME=AOSP
4 PLATFORM_VERSION=AOSP
5 TARGET_PRODUCT=full
6 TARGET_BUILD_VARIANT=eng
7 TARGET_SIMULATOR=
8 TARGET_BUILD_TYPE=release
9 TARGET_BUILD_APPS=
10 TARGET_ARCH=arm
11 TARGET_ARCH_VARIANT=armv5te
12 HOST_ARCH=x86
13 HOST_OS=linux
14 HOST_BUILD_TYPE=release
15 BUILD_ID=OPENMASTER
16 ============================================
17 make:进入目录'/home/q/Workspace/Andriod/source'
18 build/core/base_rules.mk:78: *** Module name: test-libstl
19 build/core/base_rules.mk:79: *** Makefile location: /home/q/Workspace/Andriod/NDK/samples/test-libstdc++/jni
20 build/core/base_rules.mk:80: *
21 build/core/base_rules.mk:81: * Each module must use a LOCAL_MODULE_TAGS in its
22 build/core/base_rules.mk:82: * Android.mk. Possible tags declared by a module:
23 build/core/base_rules.mk:83: *
24 build/core/base_rules.mk:84: *     optional, debug, eng, tests, samples
25 build/core/base_rules.mk:85: *
26 build/core/base_rules.mk:86: * If the module is expected to be in all builds
27 build/core/base_rules.mk:87: * of a product, then it should use the
28 build/core/base_rules.mk:88: * "optional" tag:
29 build/core/base_rules.mk:89: *
30 build/core/base_rules.mk:90: *    Add "LOCAL_MODULE_TAGS := optional" in the
31 build/core/base_rules.mk:91: *    Android.mk for the affected module, and add
32 build/core/base_rules.mk:92: *    the LOCAL_MODULE value for that component
33 build/core/base_rules.mk:93: *    into the PRODUCT_PACKAGES section of product
34 build/core/base_rules.mk:94: *    makefile(s) where it's necessary, if
35 build/core/base_rules.mk:95: *    appropriate.
36 build/core/base_rules.mk:96: *
37 build/core/base_rules.mk:97: * If the component should be in EVERY build of ALL
38 build/core/base_rules.mk:98: * products, then add its LOCAL_MODULE value to the
39 build/core/base_rules.mk:99: * PRODUCT_PACKAGES section of
40 build/core/base_rules.mk:100: * build/target/product/core.mk
41 build/core/base_rules.mk:101: *
42 build/core/base_rules.mk:102: *** user tag detected on new module - user tags
43 are only supported on legacy modules。 停止。
44 make:离开目录“/home/q/Workspace/Andriod/source”

4. 根据上面的提示编译出错,并根据提示在Android.mk里面添加 “LOCAL_MODULE_TAGS := optional”

1 # A simple test for the minimal standard C++ library
2 #
3   
4 LOCAL_PATH := $(call my-dir)
5   
6 include $(CLEAR_VARS)
7 LOCAL_MODULE_TAGS := optional #add to here
8 LOCAL_MODULE := test-libstl
9 LOCAL_SRC_FILES := test-libstl.cpp
10 include $(BUILD_EXECUTABLE)

再次运行上面的命令编译。

3. 使用源码自带Toolchain

将上面的方法中m、mm、mmm替换成make

1 q@g:~/Workspace/Andriod/source$ make libsimplejni showcommands
2 ============================================
3 PLATFORM_VERSION_CODENAME=AOSP
4 PLATFORM_VERSION=AOSP
5 TARGET_PRODUCT=full
6 TARGET_BUILD_VARIANT=eng
7 TARGET_SIMULATOR=
8 TARGET_BUILD_TYPE=release
9 TARGET_BUILD_APPS=
10 TARGET_ARCH=arm
11 TARGET_ARCH_VARIANT=armv5te
12 HOST_ARCH=x86
13 HOST_OS=linux
14 HOST_BUILD_TYPE=release
15 BUILD_ID=OPENMASTER
16 ============================================
17 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
18 find: `out/target/common/docs/gen': 没有那个文件或目录
19 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
20 find: `out/target/common/docs/gen': 没有那个文件或目录
21 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
22 find: `out/target/common/docs/gen': 没有那个文件或目录
23 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
24 find: `out/target/common/docs/gen': 没有那个文件或目录
25 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
26 find: `out/target/common/docs/gen': 没有那个文件或目录
27 target thumb C++: libsimplejni <= development/samples/SimpleJNI/jni/native.cpp
28 prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-g++  -I dalvik/libnat
29 ivehelper/include/nativehelper   -I development/samples/SimpleJNI/jni   -I out
30 /target/product/generic/obj/SHARED_LIBRARIES/libsimplejni_intermediates   -I o
31 ut/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates   -I d
32 alvik/libnativehelper/include/nativehelper   -I system/core/include   -I hardw
33 are/libhardware/include   -I hardware/libhardware_legacy/include   -I hardware
34 /ril/include   -I dalvik/libnativehelper/include   -I frameworks/base/include
35   -I frameworks/base/opengl/include   -I frameworks/base/native/include   -I e
36 xternal/skia/include   -I out/target/product/generic/obj/include   -I bionic/l
37 ibc/arch-arm/include   -I bionic/libc/include   -I bionic/libstdc++/include
38 -I bionic/libc/kernel/common   -I bionic/libc/kernel/arch-arm   -I bionic/libm
39 /include   -I bionic/libm/include/arch/arm   -I bionic/libthread_db/include  -
40 -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funw
41 ind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security -fno-sh
42 ort-enums -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__
43 ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/A
44 ndroidConfig.h -I system/core/include/arch/linux-arm/ -Wno-psabi -mthumb-inter
45 work -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-a
46 rith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequ
47 ence-point -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-func
48 tions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-register
49 s -DNDEBUG -UDEBUG -fvisibility-inlines-hidden -DANDROID -fmessage-length=0 -W
50  -Wall -Wno-unused -Winit-self -Wpointer-arith -Wsign-promo -Werror=return-typ
51 e -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -UD
52 EBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64
53 -fno-rtti       -MD -o out/target/product/generic/obj/SHARED_LIBRARIES/libsimp
54 lejni_intermediates/native.o development/samples/SimpleJNI/jni/native.cpp
55 target SharedLib: libsimplejni (out/target/product/generic/obj/SHARED_LIBRARIE
56 S/libsimplejni_intermediates/LINKED/libsimplejni.so)
57 prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-g++ -nostdlib -Wl,-so
58 name,libsimplejni.so -Wl,-T,build/core/armelf.xsc -Wl,--gc-sections -Wl,-share
59 d,-Bsymbolic -Lout/target/product/generic/obj/lib    out/target/product/generi
60 c/obj/SHARED_LIBRARIES/libsimplejni_intermediates/native.o            out/targ
61 et/product/generic/obj/lib/crtbegin_so.o -Wl,--whole-archive   -Wl,--no-whole-
62 archive   -llog -lutils -lc -lstdc++ -lm  -o out/target/product/generic/obj/SH
63 ARED_LIBRARIES/libsimplejni_intermediates/LINKED/libsimplejni.so  -Wl,-z,noexe
64 cstack    -Wl,--no-undefined  prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/
65 ../lib/gcc/arm-eabi/4.4.3/libgcc.a out/target/product/generic/obj/lib/crtend_s
66 o.o
67 target Non-prelinked: libsimplejni (out/target/product/generic/symbols/system/
68 lib/libsimplejni.so)
69 out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/SHARED_LIBRARIE
70 S/libsimplejni_intermediates/LINKED/libsimplejni.so out/target/product/generic
71 /symbols/system/lib/libsimplejni.so
72 target Strip: libsimplejni (out/target/product/generic/obj/lib/libsimplejni.so)
73 out/host/linux-x86/bin/soslim --strip --shady --quiet out/target/product/gener
74 ic/symbols/system/lib/libsimplejni.so --outfile out/target/product/generic/obj
75 /lib/libsimplejni.so
76 Install: out/target/product/generic/system/lib/libsimplejni.so
77 out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/lib/libsimplejn
78 i.so out/target/product/generic/system/lib/libsimplejni.so

通过参数中的showcommand可以得到编译的具体命令。在输出中可以看到

1 find: `frameworks/base/frameworks/base/docs/html': 没有那个文件或目录
2 find: `out/target/common/docs/gen': 没有那个文件或目录

的错误,此错误可以忽略,不会影响代码的编译。如果实在觉得影响美观可以重新下载下载源码编译。如果觉得下载时间太长可以按如下步骤解决:
1. 删除源码下除了“.repo”文件夹外的所有文件夹

1 cd /android/source
2 rm -rf *

2. 重新同步服务器

1 repo sync

因为本地仓库中已经有了源文件,所以不会花费很长时间。

参考:

Building the System[OL], source.android.com/source/building.html

在Android系统上使用busybox——最简单的方法

2011 年 07 月 22 日 分类目录 :Android 1

Android是基于Linux系统的,在学习和使用Android系统时,不可避免的要和Terminal打交道。但是Android自带的Terminal emulator实在是简陋,连一些基本的命令都不具备。有没有什么解决方法呢?有的,这便是被称为“嵌入式Linux中的瑞士军刀”的Busybox。

      一、BusyBox
      BusyBox 是标准 Linux 工具的一个单个可执行实现。BusyBox 包含了一些简单的工具,例如 cat 和 echo,还包含了一些更大、更复杂的工具,例如 grep、find、mount 以及 telnet。有些人将 BusyBox 称为 Linux 工具里的瑞士军刀。简单的说BusyBox就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令。

      二、安装

  1. 取得设备的Root权限(网上查找)。
  2. 下载Busybox(下载)编译安装,也可以直接下载binary文件(下载)。
  3. 将Busybox binary文件拷贝到Android系统的/system/xbin目录下。

      三、使用

1.  在安装完后便可以使用了。使用方法:busybox command,例如,busybox ls
       
       看颜色是不是变了。
      
       2. 因为系统里面也有ls命令,如果直接调用ls将会调用系统的ls,这样要想使用busybox的命令就必须加上busybox字符。这样很不方便,有没有办法可以省去这样麻烦呢?

方法一: 使用命令 alies,例如:
        # alias ls=’busybox ls’
     这个方法的缺点是重启终端,又会恢复原样。

方法二: 删除或者重命名 /system/bin/toolbox

参考文献:

  1. 为Android安装BusyBox —— 完整的bash shell[OL].http://www.cnblogs.com/xiaowenji/archive/2011/03/12/1982309.html
  2. Android自带的toolbox分析及扩展[OL].http://blog.csdn.net/a345017062/article/details/6250619

android, busybox

Android 存档相关推荐

  1. 【Android 逆向】Android 进程注入工具开发 ( 注入代码分析 | 调试进程 ATTACH 附着目标进程 | 读取目标函数寄存器值并存档 )

    文章目录 一.调试进程 ATTACH 附着目标进程 二.读取目标函数寄存器值并存档 1.主要操作流程 2.ptrace 函数 PTRACE_GETREGS 读取寄存器值 一.调试进程 ATTACH 附 ...

  2. 在Android手机上将Minecraft国际版地图存档导入中国版(亲测有效)

    一. mc国际版与中国版不互通 网易在2017年获得了Minecraft在中国大陆地区的代理权,而本人之前一直在玩的是后来所谓的mc国际版,有的地图存档也肝了两三年.如果让我放弃原有的地图存档去入手网 ...

  3. android 备份游戏数据,用于Android游戏存档备份和存档还原的教程(图形中的详细信息)...

    现在有越来越多的Android游戏,并且更新越来越快. 许多玩家由于滑动或更新而意外删除了游戏,这使得难以玩的游戏档案会立即消失,或者钦佩他人的完美表现. 档案希望免费使用,下面为所有人介绍常见And ...

  4. Android 游戏存档位置分析

    android 游戏存档分析, 这种存档游戏,对android 和ios 系统能通用; android obb 跟据官网介绍:obb没有固定格式,官网给出里zip压缩格式的一个例子,但是大部分游戏都要 ...

  5. 【Android 逆向】Android 进程注入工具开发 ( 调试进程中寄存器的作用 | 通过 EIP 寄存器控制程序运行 | EIP 寄存器的存档与恢复 )

    文章目录 一.调试进程中寄存器的作用 二.通过 EIP 寄存器控制程序运行 三.EIP 寄存器的存档与恢复 一.调试进程中寄存器的作用 内存是一个线性结构 , 将动态库加载到内存中后 , 每个动态库文 ...

  6. mc穿越时空地图android,我的世界RPG地图穿越时空地图存档下载

    我的世界RPG地图穿越时空地图存档是一个非常出名的RPG地图存档,今天17173小编就为大家带来我的世界RPG地图穿越时空地图存档下载. 我的世界RPG地图穿越时空地图存档: 地图名称:穿越时空 地图 ...

  7. android ppsspp 存档位置,ppsspp怎么用,ppsspp怎么用psp存档

    如何使用Android PSP模拟器PPSSPP? PPSSPP使用起来并不复杂. 尽管它仅以英语提供,但并不难理解(如果您不理解设置中的术语,估计会翻译成中文.不理解). PPSSPP主界面的左侧显 ...

  8. android township 游戏存档备份,游戏闪退存档全没了?不要怕,可以这样备份与还原游戏存档!...

    不少朋友可能有过这样的苦恼,好不容易在第三方商店下到好玩的修改版游戏,结果玩了一阵子突然提示证书失效,游戏闪退打不开了,只能卸载重装.可是卸载后,游戏之前的存档就没了,又得耗费大量的时间重头再来,这样 ...

  9. android township 游戏存档备份,安卓游戏存档备份与存档还原的教程(图文详细)

    现在安卓游戏越来越多,更新也越来越快,很多玩家由于手滑或是更新时误删游戏,导致辛辛苦苦打出来的游戏存档瞬间消失,又或是羡慕别人的完美存档想拿来自用,下面就为大家介绍常用的安卓游戏的存档备份和恢复方法. ...

最新文章

  1. 数据库报错: SQLCODE: -418, SQLSTATE: 42610, SQLERRMC: null
  2. 查询反模式 - GroupBy、HAVING的理解
  3. h3c怎么创建虚拟服务器,h3c 设置虚拟服务器
  4. allocator类编程实验
  5. maven install (window 7)
  6. Tomcat项目部署过程中的问题
  7. TRACE (VC)
  8. Python 线程(二):简单锁实现线程同步
  9. [Python] L1-045 宇宙无敌大招呼-PAT团体程序设计天梯赛GPLT
  10. linux 命令之df持续更新中~
  11. 二分法07:寻找峰值
  12. JedisCluster设置密码
  13. 数学_一文搞懂极大似然估计
  14. Linux安装python第三方库
  15. 柴静:我只是讨厌屈服
  16. Nginx配置防盗链和内核参数优化
  17. Google浏览器离线安装包下载
  18. 学习推荐书籍--C语言
  19. [MySQL 源码] Innodb Pessimistic Insert流程
  20. 有房没房,日子过的都是心态

热门文章

  1. 微信投票系统java开发_微信投票系统 v3.0
  2. 【搜索+DP】codevs1066-引水入城
  3. 不掉帧不卡顿的游戏直播画面看起来爽爆了,求网络推流搭建方案
  4. 让bootstrap兼容ie6 ie7 ie8 ie9 ie10 ie11的解决方法
  5. 1分钟为Win10瘦身!把吃掉的硬盘找回来
  6. 坐下来谈谈如何写好一份简历?
  7. 无法成功执行catalog.sql,ORA-04045 ORA-04064
  8. matplotlib 源码解析标题实现(窗口标题,标题,子图标题不同之间的差异)
  9. SpringCache源码学习笔记
  10. stm32 c语言编程pdf,STM32-MCX314 基于C语言编写的STM32控制运动控制芯片MCX314的整套控制程序 - 下载 - 搜珍网...