Home Android Tutorials How to build and run a native c application on android emulator
How to build and run a native c application on android emulator PDF Print E-mail

* to start emulator
  ./emulator -console
 

* to transfer 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 ANDROID EMULATOR
 

References
 

Native C "Hello World" working in emulator
http://groups.google.com/group/android-developers/browse_thread/threa...
 

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_toolchains/arm/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 HELLO WORLD CODE
//
// HelloAndroid.cpp
//
//
 

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 

class MyName
{
  public:
    void getname( void );
    void sayhello( void );
 

  private:
    char name[ 255 ];
 

 

};

 
void MyName::getname( void )
{
  cout << "What is your name? ";
  cin >> name;
 

 

}

 
void MyName::sayhello( void )
{
  cout << "Welcome " << name << " to the world of Android" << endl;
 

 

}

 
MyName name;
 

int main( int argc, char *argv[] )
{
  name.getname();
  name.sayhello();
  return 0;
 

}

 

 

Source: android google group

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
Comments (0)
Only registered users can write comments!