技术开发 频道

Android C编程技巧

  【IT168 技术文档】运行模拟器

  emulator -console

  * 将文件写入到模拟器的userdata.img文件中

  adb push

  *将一个目录拷贝到模拟器中,包括子目录

  adb push

  * 将一个目录从模拟器中拷出来

  adb pull

  * 使得模拟器可以运行arm代码.

  使用GNU/ARM Linux编译器编译你的应用程序就可以了

  * 在模拟器里面运行shell,需要先运行模拟器

  adb shell

  *运行模拟器中的一个控制台程序

  adb shell

  *连接模拟器的控制台

  telnet localhost 5554/6/8

  运行C程序

  参考文献

  Native C "Hello World" working in emulator

  http://groups.google.com/group/a ... wse_thread/threa...

  Native C Applications for Android

  http://benno.id.au/blog/2007/11/13/android-native-apps

  步骤

  * 下载GNU/ARM编译工具

  http://www.codesourcery.com/gnu_toolchains/arm/download.html

  * 编写c/c++代码.

  * 使用GNU/ARM Linux 工具创建一个应用程序,不使用动态链接库

  ex. arm-none-linux-gnueabi-g++.exe -static -o hello HelloAndroid.cpp

  * 启动模拟器

  $SDK_ROOT/tools/emulator.exe

  * 在命令行窗口运行 abd将编译好的hello程序放入模拟器的磁盘

  adb push hello /system/sbin/hello

  * 让hello文件变成可执行程序,不要使用 chmod ugo+x

  adb shell chmod 777 /system/sbin/hello

  * 运行hello程序

  adb shell

  cd /system/sbin/

  hello

  EXAMPLE HELLO WORLD CODE

  //   // HelloAndroid.cpp   //   //   #include   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;   }
0
相关文章