新聞中心

        Android C編程技巧

        作者: 時間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

        Android C編程技巧

        本文引用地址:http://www.104case.com/article/201610/305822.htm

        運行模擬器

        emulator -console

        * 將文件寫入到模擬器的userdata.img文件中

        adb push

        *將一個目錄拷貝到模擬器中,包括子目錄

        adb push

        * 將一個目錄從模擬器中拷出來

        adb pull

        * 使得模擬器可以運行arm代碼.

        使用GNU/ARM Linux編譯器編譯你的應(yīng)用程序就可以了

        * 在模擬器里面運行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 工具創(chuàng)建一個應(yīng)用程序,不使用動態(tài)鏈接庫

        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文件變成可執(zhí)行程序,不要使用 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;

        }



        關(guān)鍵詞:

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 农安县| 阿拉善盟| 克什克腾旗| 太仆寺旗| 铁岭县| 岳阳市| 南澳县| 尖扎县| 祁门县| 临沂市| 西华县| 云梦县| 台江县| 宜宾市| 色达县| 沾益县| 筠连县| 鄱阳县| 万荣县| 肃北| 天全县| 三门峡市| 三明市| 宁晋县| 巧家县| 怀远县| 民乐县| 玉林市| 顺昌县| 县级市| 扎兰屯市| 贡嘎县| 定兴县| 林口县| 嵩明县| 澎湖县| 新沂市| 濮阳市| 垫江县| 独山县| 峨眉山市|