Results 1 to 3 of 3
  1. #1
    offline Maybe Modder
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0

    Native C++ "Hello World" working in emulator

    Android OS Tips

    * to start emulator
    ./emulator -console

    * to xfer a file to emulator; this is stored in emulator's userdata.img file
    adb push <file> <dst file>

    * to copy a file or a directory recursively to emulator
    adb push <source> <destination>

    * to copy a file or a directory recursively from emulator
    adb pull <source> <destination>

    * emulator can run native ARM Linux code.
    build your apps using GNU/ARM Linux toolchain and then run in emulator.

    * to get a shell on the emulator
    adb shell

    * to run a console app on Android emulator
    adb shell <Linux command>

    * to connect to emulator console for specific commands
    telnet localhost 5554/6/8


    Building and Running a native C++ App on the Android Emulator


    References

    Native C "Hello World" working in emulator
    http://groups.google.com/group/andro...f09cb4dd9687cc

    Native C Applications for Android
    http://benno.id.au/blog/2007/11/13/android-native-apps

    Steps:
    * download and install GNU/ARM Linux tool chain
    http://www.codesourcery.com/gnu_tool.../download.html

    * create C/C++ code. see below for sample code.

    * build app without dynamic libraries using GNU/ARM Linux toolchain
    ex. arm-none-linux-gnueabi-g++.exe -static -o hello HelloAndroid.cpp

    * start emulator in Windows by double clicking on $SDK_ROOT/tools/emulator.exe

    * in a Windows Command window, use "adb" to xfer executable to emulator disk
    adb push hello /system/sbin/hello

    * make your app executable; do not use chmod ugo+x
    adb shell chmod 777 /system/sbin/hello

    * run your app in a console on the emulator
    adb shell
    cd /system/sbin/
    hello

    EXAMPLE C++ CODE:
    Code:
    //
    // HelloAndroid.cpp
    //
    //
    
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
    
    class ReVan
    {
      public:
        void getname( void );
        void sayhello( void );
    
      private:
        char name[ 255 ];
    **;
    
    void ReVan::getname( void )
    {
      cout << "What is your name? ";
      cin >> name;
    **
    
    void ReVan::sayhello( void )
    {
      cout << "Welcome " << name << " to the world of Android" << endl;
    **
    
    ReVan name;
    
    int main( int argc, char *argv[] )
    {
      name.getname();
      name.sayhello();
      return 0;
    **

  2. #2
    Kyle Matthews's Avatar
    offline Owner / Founder - ModMyMobile
    aka poetic_folly
    Join Date
    Sep 2006
    Location
    good old Tampa, FL
    Posts
    9,749
    Thanks
    870
    Thanked 1,867 Times in 838 Posts
    Downloads
    221
    Uploads
    253
    Source: anddev.org.
    Visit our iPhone forum and check it out! Kyle Matthews

  3. #3
    offline Itty Bitty Modder
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    Keep up the good work..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •