09年智手各组组长,组员重新招募中 发贴得礼品有实物,有金币和道具 重新招募09年各版版主 每月获奖名单
新人报到加分贴 对我们的意见告诉这里 新增奖品及奖励办法 广告招商
返回列表 回复 发帖

ANDROID c编程技巧(一)[转]

ANDROID c编程技巧(一)[转]转载http://www.androidcn.net/viewthread.php?tid=4&extra=page%3D1

ANDROID 技巧

运行模拟器
  emulator -console


* 将文件写入到模拟器的userdata.img文件中
  adb push <file> <dst file>


*将一个目录拷贝到模拟器中,包括子目录
  adb push <source> <destination>


* 将一个目录从模拟器中拷出来
  adb pull <source> <destination>


* 使得模拟器可以运行arm代码.
  使用GNU/ARM Linux编译器编译你的应用程序就可以了

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


*运行模拟器中的一个控制台程序
  adb shell <Linux command>


*连接模拟器的控制台
  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 <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;
}
http://www.wmtxt.com手机小说下载
返回列表