Happy porting x86 application to android
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Happy porting x86 application to android

on

  • 8,225 views

This slide described how to port x86 application to arm-based android platform, and 2 examples are included

This slide described how to port x86 application to arm-based android platform, and 2 examples are included

Statistics

Views

Total Views
8,225
Views on SlideShare
8,157
Embed Views
68

Actions

Likes
0
Downloads
120
Comments
3

11 Embeds 68

http://owen-hsu.blogspot.com 29
http://owen-hsu.blogspot.tw 17
https://twitter.com 8
http://www.slashdocs.com 4
http://owen-hsu.blogspot.hk 2
http://translate.googleusercontent.com 2
http://owen-hsu.blogspot.ca 2
http://owen-hsu.blogspot.de 1
http://owen-hsu.blogspot.kr 1
http://owen-hsu.blogspot.jp 1
http://twitter.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hello sanchess33,
    You can check your Application.mk and Android.mk, the APP_MODULES in Application.mk and LOCAL_MODULE in Android.mk should be the same, and the app folder name should be the same with your make command, like make APP={app folder name}.
    Are you sure you want to
    Your message goes here
    Processing…
  • this is output

    root@debian:/android/ndk# make APP=wget V=1
    Android NDK: Building for application s 'wget'
    make: *** No rule to make target `wget', needed by `ndk-app-wget'. Stop.

    Thanks
    Are you sure you want to
    Your message goes here
    Processing…
  • congratulations for the article, very rich and useful.
    I'm having a problem to compile wget with ndk.
    I followed yours instructions but I get the following error

    #root@debian:/android/ndk# make APP=wget V1
    #Android NDK: Building for application s 'wget'
    #make: *** No rule to make target `V1'. Stop.

    Thanks in advance.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Happy porting x86 application to android Presentation Transcript

  • 1. Happy Porting x86 Application to Android 2010-07 Owen Hsu
  • 2. Outline
    • Motivation
    • Solutions
    • Examples
  • 3. Why Bother?
    • Different instruction set
      • Most applications were programmed under x86 architecture, Android is run under ARM by default.
    • Different variable types
      • There is NO standard C library in Android, it provides Bionic C library instead.
  • 4. Solutions?
    • The Traditional Make way
    • The NDK way
  • 5. The Traditional Make Way
    • Loop
      • 1. Configure
      • 2. Modify the Makefile
      • 3. Make
      • 4. Patch
  • 6. The NDK Way
    • 1. Configure
    • 2. Write Android Makefile
    • 3. Patch code
    • 4. Run
  • 7. Example
    • Wget – Run as Android Executable
    • Curl - Run as Android Shared Library
  • 8. Note
    • These examples are made by NDK r3, the installation path is /usr/local/src/android-ndk-r3, it also marked as /PATH/TO/NDK in later slide
    • The version of wget is 1.11.4, it is available in http://ftp.gnu.org/gnu/wget/wget-1.11.4.tar.gz , or in http://goo.gl/0inP
    • The version of Curl is 7.20.0, it is available in http://curl.haxx.se/download/curl-7.20.0.tar.bz2 , or in http://goo.gl/qGz6
  • 9. Wget Porting by NDK - 1. Configure
    • 1.1 Create NDK apps
      • # mkdir –p /PATH/TO/NDK/apps/wget/project/jni
      • # cd /PATH/TO/NDK/apps/wget/project/jni
    • 1.2 Copy wget source to NDK apps
      • # cp –Rf /usr/local/src/wget-1.11.4/* .
    • 1.3 Disable most features, and create the Makefile
      • # ./configure --disable-opie --disable-digest --disable-ntlm --disable-debug --disable-largefile --disable-ipv6 --disable-nls --without-ssl
    • Reference: Android_Makefile_Internal.pdf
  • 10. Wget Porting by NDK - 2. Write Android Makefile
    • 2.1 Create NDK Application.mk
      • # vim /PATH/TO/NDK/apps/wget/Application.mk
      • # begin code
      • APP_PROJECT_PATH := $(call my-dir)/project
      • APP_MODULES := wget
      • # end code
    • 2.2 Create NDK Android.mk
      • # vim /PATH/TO/NDK/apps/project/jni/Android.mk
      • # begin code
      • include $(call all-subdir-makefiles)
      • # end code
      • # vim /PATH/TO/NDK/apps/project/jni/src/Android.mk
      • # begin code
      • LOCAL_PATH := $(call my-dir)
      • include $(CLEAR_VARS)
      • LOCAL_MODULE := wget
      • LOCAL_SRC_FILES := alloca.c cmpt.c connect.c convert.c cookies.c ftp-basic.c ftp-ls.c ftp-opie.c ftp.c getopt.c hash.c host.c html-parse.c html-url.c http.c init.c log.c main.c netrc.c progress.c ptimer.c recur.c res.c retr.c safe-ctype.c snprintf.c spider.c url.c utils.c version.c xmalloc.c
      • include $( BUILD_EXECUTABLE )
      • # end code
  • 11. Wget Porting by NDK - 3. Patch code
    • 3.1 Test run
      • # cd /PATH/TO/NDK
      • # make APP=wget V=1
    • 3.2 Check out the error message
      • apps/wget/project/jni/src/sysdep.h:65: error: two or more data types in declaration specifiers
      • apps/wget/project/jni/src/sysdep.h:203:3: error: #error "Cannot determine a 32-bit unsigned integer type"
      • apps/wget/project/jni/src/sysdep.h:211: error: conflicting types for 'uintptr_t‘
      • apps/wget/project/jni/src/sysdep.h:216: error: conflicting types for 'intptr_t'
      • apps/wget/project/jni/src/wget.h:162: error: redefinition of typedef 'off_t'
      • apps/wget/project/jni/src/options.h:119: error: expected specifier-qualifier-list before 'wgint'
  • 12. Wget Porting by NDK - 3. Patch code
    • 3.3 Patch code
      • Patch src/sysdep.h
      • Patch src/utils.c
      • Patch src/wget.h
      • See: http://goo.gl/k2gt
    • 3.4 Make & Get executable file
      • # cd /PATH/TO/NDK
      • # make APP=wget V=1
      • Result
        • Executable : wget
        • Install : wget => apps/wget/project/libs/armeabi
  • 13. Wget Porting by NDK - 4. Run
    • 4.1 Start the emulator
      • # emulator –avd Donut
    • 4.2 Upload the wget binary under /PATH/TO/NDK/apps/wget/project/libs/armeabi
      • # adb push wget /system/bin
    • 4.3 Run the application
      • # adb shell chmod 755 /system/bin/wget
      • # adb shell /system/bin/wget http://goo.gl/AsP5
  • 14. Wget Porting Reference
    • http://jacob.hoffman-andrews.com/android/wget /
  • 15. The Diff/Patch Tool HOWTO
    • diff
      • Compare the difference between two files
      • Syntax:
        • diff [OPTION] SOURCE DESTINATION
        • -r: recursive
        • -N: new file
        • -u: uniform format
    • patch
      • Patch/restore file by patch-file
      • Syntax:
        • patch [OPTION] < PATCH_FILE
        • -p0: from current directory
        • -p1: ignore the first level of directory
        • -R: reverse
        • -E: remove-empty-files
  • 16. Example of Patch Single File (1/4)
    • 1. Create test file
      • # cat >> test0 << EOF
      • > 0000
      • > 0000
      • > EOF
      • # cat >> test1 << EOF
      • > 1111
      • > 1111
      • > EOF
  • 17. Example of Patch Single File (2/4)
    • 2. Create patch file
      • # diff –uN test0 test1 > test1.patch
      • # less test1.patch
      • --- test0 2009-06-04 18:19:07.000000000 +0800
      • +++ test1 2009-06-04 18:19:13.000000000 +0800
      • @@ -1,2 +1,2 @@
      • -0000
      • -0000
      • +1111
      • +1111
  • 18. Description of Patch file
    • Description:
      • Header: --- old file, +++ new file
      • Hunk: @@ line number which is modified
    • + new added
    • - new deleted
    • Example:
    • // Header
    • --- test0 2009-06-04 18:19:07.000000000 +0800
    • +++ test1 2009-06-04 18:19:13.000000000 +0800
    • // Hunk
    • @@ -1,2 +1,2 @@
    • -0000
    • -0000
    • +1111
    • +1111
  • 19. Example of Patch Single File (3/4)
    • 3. Patch the target file
      • # patch –p0 < test1.patch
      • # less test0
      • 1111
      • 1111
  • 20. Example of Patch Single File (4/4)
    • 4. Reverse the patched file
      • # less test0
      • 1111
      • 1111
      • # patch –RE –p0 < test1.patch
      • # less test0
      • 0000
      • 0000
  • 21. Example of Patch Multiple Files
    • 1. Create test file
      • # mkdir prj0
      • # cp test0 prj0
      • # cd prj0
      • # cat >> foo0 << EOF
      • > prj0/foo0
      • > EOF
      • # cd ..
      • # mkdir prj1
      • # cp test1 prj1
      • # cd prj1
      • # cat >> foo1 << EOF
      • > prj1/foo1
      • > EOF
      • # cd ..
  • 22. Example of Patch Multiple Files
    • 2. Create patch file
      • # diff –ruN prj0 prj1 > prj1.patch
      • # less prj1.patch
      • diff -ruN prj0/foo0 prj1/foo0
      • --- prj0/foo0 2009-06-04 18:37:28.000000000 +0800
      • +++ prj1/foo0 1970-01-01 08:00:00.000000000 +0800
      • @@ -1 +0,0 @@
      • -prj0/foo0
      • diff -ruN prj0/foo1 prj1/foo1
      • --- prj0/foo1 1970-01-01 08:00:00.000000000 +0800
      • +++ prj1/foo1 2009-06-04 18:37:40.000000000 +0800
      • @@ -0,0 +1 @@
      • +prj1/foo1
      • diff -ruN prj0/test0 prj1/test0
      • --- prj0/test0 2009-06-04 18:31:55.000000000 +0800
      • +++ prj1/test0 1970-01-01 08:00:00.000000000 +0800
      • @@ -1,2 +0,0 @@
      • -0000
      • -0000
      • diff -ruN prj0/test1 prj1/test1
      • --- prj0/test1 1970-01-01 08:00:00.000000000 +0800
      • +++ prj1/test1 2009-06-04 18:33:29.000000000 +0800
      • @@ -0,0 +1,2 @@
      • +1111
      • +1111
  • 23. Example of Patch Multiple Files
    • 3. Patch the target file
      • # cd prj0
      • # patch -p1 < ../prj1.patch
      • # ls
      • foo1 test1
  • 24. Example of Patch Multiple Files
    • 4. Reverse the patched file
      • # ls
      • foo1 test1
      • # patch –RE –p1 < ../prj1.patch
      • # ls
      • foo0 test0
  • 25. Diff & Patch Reference
    • http://www.xspace.idv.tw/bo_blog/read.php?97
    • http://www.linuxforums.org/articles/using-diff-and-patch_80.html
  • 26. Curl Porting by NDK - 1. Configure
    • 1.1 Create NDK apps
      • # mkdir –p /PATH/TO/NDK/apps/curl/project/jni
      • # cd /PATH/TO/NDK/apps/libcurl/project/jni
    • 1.2 Copy curl source to NDK apps
      • # cp –Rf /usr/local/src/curl-7.20.0/* .
    • 1.3 Disable most features, and create Makefile
      • # ./configure --disable-debug --disable-optimize --disable-warnings --disable-curldebug --disable-ares --disable-dependency-tracking --disable-largefile --disable-libtool-lock --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-manual --disable-ipv6 --disable-verbose --disable-sspi --disable-crypto-auth --disable-cookies --disable-hidden-symbols --disable-soname-bump --without-ssl --without-zlib --without-gnutls --without-nss --without-ca-path --without-libssh2 --without-libidn
  • 27. Curl Porting by NDK - 1. Configure
    • Notice:
      • Config with &quot;--disable-nonblocking&quot; will cause the abnormal data transfer
  • 28. Curl Porting by NDK - 2. Write Android Makefile
    • Fortunately, a sample android.mk in source is included, we just need to do some modifications
    • Two-libs format:
      • Compile first library as shared library
      • Compile second library as executable file
  • 29. Curl Porting by NDK - 3. Patch code
    • 3.1 Patch code
      • Patch project/jni/lib/connect.c
      • Patch project/jni/lib/url.c
      • See: http://goo.gl/LHbR
    • 3.2 Add C program to invoke Curl library
    • 3.3 Make & Get shared library
      • # cd /PATH/TO/NDK
      • # make APP=c-call-curl V=1
      • Result:
      • SharedLibrary : libcurl.so
      • Install : libcurl.so => apps/c-call-curl/project/libs/armeabi
      • Compile thumb : c-call-curl <= apps/c-call-curl/project/jni/simple.c
      • Executable : c-call-curl
      • Install : c-call-curl => apps/c-call-curl/project/libs/armeabi
  • 30. Curl Porting by NDK - 4. Run
    • 4.1 Start the emulator
      • # emulator –avd Donut
    • 4.2 Upload the Curl library & C program under /PATH/TO/NDK/apps/curl/project/libs/armeabi
      • # adb remount
      • # adb push c-call-curl /system/bin
      • # adb push libcurl.so /system/lib
    • 4.3 Run the application
      • # adb shell chmod 755 /system/bin/c-call-curl
      • # adb shell /system/bin/c-call-curl
  • 31. Curl Porting Reference
    • http://curl.haxx.se/mail/lib-2009-12/0071.html