導航:首頁 > 源碼編譯 > android代碼編譯x86

android代碼編譯x86

發布時間:2022-04-27 04:12:36

A. android 6.0的源碼編譯問題

看報錯信息是找不到這個文件build/kati/Makefile.ckati。可能沒有下載完全?
可以對比下別人的代碼看有沒有,或者可以問一些朋友要這個文件,實在沒有。在ninjia.mk中把這行注釋掉在編譯試試。先make clean

B. 自己可以編譯安卓源碼嗎

用最新的Ubuntu 16.04,請首先確保自己已經安裝了Git.沒安裝的同學可以通過以下命令進行安裝:

sudo apt-get install git git config –global user.email 「[email protected]」 git config –global user.name 「test」

其中[email protected]為你自己的郵箱.

簡要說明

android源碼編譯的四個流程:1.源碼下載;2.構建編譯環境;3.編譯源碼;4運行.下文也將按照該流程講述.

源碼下載

由於某牆的原因,這里我們採用國內的鏡像源進行下載.
目前,可用的鏡像源一般是科大和清華的,具體使用差不多,這里我選擇清華大學鏡像進行說明.(參考:科大源,清華源)

repo工具下載及安裝

通過執行以下命令實現repo工具的下載和安裝

mkdir ~/binPATH=~/bin:$PATHcurl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repochmod a+x ~/bin/repo

補充說明
這里,我來簡單的介紹下repo工具,我們知道AOSP項目由不同的子項目組成,為了方便進行管理,Google採用Git對AOSP項目進行多倉庫管理.在聊repo工具之前,我先帶你來聊聊多倉庫項目:

我們有個非常龐大的項目Pre,該項目由很多個子項目R1,R2,...Rn等組成,為了方便管理和協同開發,我們為每個子項目創立自己的倉庫,整個項目的結構如下:


這里寫圖片描述

執行完該命令後,再使用make命令繼續編譯.某些情況下,當你執行jack-admin kill-server時可能提示你命令不存在,此時去你去out/host/linux-x86/bin/目錄下會發現不存在jack-admin文件.如果我是你,我就會重新repo sync下,然後從頭來過.

錯誤三:使用emulator時,虛擬機停在黑屏界面,點擊無任何響應.此時,可能是kerner內核問題,解決方法如下:
執行如下命令:

  • ./out/host/linux-x86/bin/emulator -partition-size 1024 -kernel ./prebuilts/qemu-kernel/arm/kernel-qemu-armv7

  • 通過使用kernel-qemu-armv7內核 解決模擬器等待黑屏問題.而-partition-size 1024 則是解決警告: system partion siez adjusted to match image file (163 MB >66 MB)

    如果你一開始編譯的版本是aosp_arm-eng,使用上述命令仍然不能解決等待黑屏問題時,不妨編譯aosp_arm64-eng試試.

    結束吧

    到現在為止,你已經了解了整個android編譯的流程.除此之外,我也簡單的說明android源碼的多倉庫管理機制.下面,不妨自己動手嘗試一下.

    C. 如何編譯android x86模擬器

    首先你需要設置一下emulator工具的目錄之類的
    要在.bashrc中新增環境變數,如下
    ANDROID_PRODUCT_OUT=~/android/out/target/proct/generic
    ANDROID_PRODUCT_OUT_bin=~/android/out/host/linux-x86/bin
    這里是設置你的輸出文件的位置和bin工具目錄
    然後在命令行輸入:
    export path=${path}:${ANDROID_PRODUCT_OUT_bin}:${ANDROID_PRODUCT_OUT};
    上面是導入了相關的配置,然後使之生效。
    source ~/.bashrc
    接著切換到輸出的system文件夾
    cd ~/android/out/target/proct/generic
    然後來創建模擬器
    emulator -system system.img -data userdata.img -ramdisk ramdisk.img
    如果你運氣夠好的話,也許現在已經在運行了,不過我運氣明顯不夠好。
    提示一:
    emulator: ERROR: You did not specify a virtual device name, and the system
    directory could not be found.
    If you are an Android sdk user, please use 『@<name>』 or 『-avd <name>』
    to start a given virtual device (see -help-avd for details).
    Otherwise, follow the instructions in -help-disk-images to start the emulator

    既然人家提示了,那就按照步驟走吧,輸入命令:
    emulator -help-avd
    接著提示如下:
    use 『-avd <name>』 to start the emulator program with a given Android
    Virtual Device (a.k.a. AVD), where <name> must correspond to the name
    of one of the existing AVDs available on your host machine.
    See -help-virtual-device to learn how to create/list/manage AVDs.
    As a special convenience, using 『@<name>』 is equivalent to using
    『-avd <name>』.
    跟著提示繼續走,輸入命令:
    emulator -help-virtual-device
    又是提示了:
    An Android Virtual Device (AVD) models a single virtual
    device running the Android platform that has, at least, its own
    kernel, system image and data partition.
    Only one emulator process can run a given AVD at a time, but
    you can create several AVDs and run them concurrently.
    You can invoke a given AVD at startup using either 『-avd <name>』
    or 『@<name>』, both forms being equivalent. For example, to launch
    the AVD named 『foo』, type:
    emulator @foo
    The 『android』 helper tool can be used to manage virtual devices.
    For example:
    android create avd -n <name> -t 1 # creates a new virtual device.
    android list avd # list all virtual devices available.
    Try 『android –help』 for more commands.
    Each AVD really corresponds to a content directory which stores
    persistent and writable disk images as well as configuration files.
    Each AVD must be created against an existing sdk platform or add-on.
    For more information on this topic, see -help-sdk-images.

    延伸1):
    Android x86模擬器Intel Atom x86 System Image配置與使用方法

    大家現在開發使用的Android 模擬器模擬的是 arm 的體系結構(arm-eabi),因此模擬器並不是運行在x86上而是模擬的arm,所以我們調試程序的時候經常感覺到非常慢,大部分開發者應該都深有體會。
    針對這種情況,前段時間intel推出了支持x86的Android模擬器,這將大大提高啟動速度和程序的運行速度,這將允許Android模擬器能夠以原始速度(真機運行速度)運行在使用intel x86處理器的電腦中,各位開發者有福了,下面將為大家展示使用方法。

    一、首先下載intel提供的 intel® Hardware Accelerated Execution Manager 1.0.1(R2)

    requirement:
    1. requires the Android* SDK to be installed (version 17 or higher). SDK17或者以上
    2.intel® processor with support for VT-x, EM64T, and Execute Disable (XD) bit functionality intel的cpu:並支持VT-X(虛擬化技術)、可擴展64位、Execute Disable bit。(均需要保證在bios中開啟Enable)
    3. At least 1 gb of available ram 1G以上內存,否則安裝不了

    滿足硬體和軟體要求之後,就可以開始安裝了,一直下一步至安裝成功。途中有個地方選擇分配給HAXM內存大小,一般默認就好,分太多會拖慢整機速度。

    安裝成功後命令行輸入sc query intelhaxm,查看運行狀態: state is: 「4 RUNNING」 ,即代表安裝成功。需要更改分配內存,重新運行一下安裝程序選擇change即可修改。
    還可以使用以下指令手動開啟和關閉:
    Stop: sc stop intelhaxm

    Start:
    sc start intelhaxm

    滿足軟硬體條件,若提示如下Error:but intel Execute Disable bit (XD) is not turned on......
    (需要開啟系統數據執行保護功能dep,下午糾結了好久才查到。官網原文:Windows* hosts may need to enable dep (Data Execution Prevention) in addition to intel XD)
    命令行使用指令:bcdedit.exe /set nx optin 打開即可,需要重啟電腦

    二、下載Intel Atom x86 System Image
    1. 從SDK Manager下載:打開SDK Manager,展開至Android2.3.3(API10)(注意:目前只有2.3.3和4.0.3(Ice Cream Sandwich)有x86的Image),需要和2.3.3的SDK Platform配合使用。

    2.使用avd Manager創建一個新的avd: Hardware Property裡面選擇gpu emulation yes 還有 Keyboard support yes

    3.開始使用飛速的模擬器吧,各種爽歪歪
    好的工具可以更有效率的開發APP,讓我們從此告別那龜速的模擬器吧

    D. android已有動態庫怎麼編譯靜態庫

    在eclipse工程目錄下建立一個jni的文件夾
    在jni文件夾中建立Android.mk和Application.mk文件

    Android.mk文件:

    Android提供的一種makefile文件,用來指定諸如編譯生成so庫名、引用的頭文件目錄、需要編譯的.c/.cpp文件和.a靜態庫文件等。詳見附件中的Android.mk。

    Application.mk文件:

    定義了項目的一些細節,比如APP_ABI := x86(編譯X86平台庫)、APP_PLATFORM := android-9(使用android-9以上的平台庫)。

    NDK 編譯和使用靜態庫、動態庫
    情況一:編譯靜態庫
    情況二:編譯動態庫
    情況三:編譯動態庫+靜態庫
    情況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)

    默認所有代碼和文件在$project/jni下,否則特殊說明。
    情況一:編譯靜態庫
    文件Android.mk:
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := hello-jni
    LOCAL_SRC_FILES := hello-jni.c
    include $(BUILD_STATIC_LIBRARY)

    文件Application.mk:
    APP_MODULES :=hello-jni

    情況二:編譯動態庫
    文件Android.mk:
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := hello-jni
    LOCAL_SRC_FILES := hello-jni.c
    include $(BUILD_SHARED_LIBRARY)
    情況三:編譯動態庫+靜態庫
    文件Android.mk:
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := mylib_static
    LOCAL_SRC_FILES := src.c
    include $(BUILD_STATIC_LIBRARY)
    include $(CLEAR_VARS)
    LOCAL_MODULE := mylib_shared
    LOCAL_SRC_FILES := src2.c
    LOCAL_STATIC_LIBRARIES := mylib_static
    include $(BUILD_SHARED_LIBRARY)
    情況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)
    文件Android.mk:
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := thirdlib1 # name it whatever
    LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libthird1.a # or $(so_path)/libthird1.so
    #LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
    include $(PREBUILT_STATIC_LIBRARY) #or PREBUILT_SHARED_LIBRARY
    include $(CLEAR_VARS)
    LOCAL_MODULE := mylib_use_thirdlib
    LOCAL_SRC_FILES := src.c
    LOCAL_STATIC_LIBRARIES := thirdlib1 #or LOCAL_SHARED_LIBRARY

    include $(BUILD_SHARED_LIBRARY) #如果編譯靜態庫,需要Application.mk
    用cd命令移至jni目錄,運行/mnt/500G/public/NDK/android-ndk-r7b/ndk-build命令,這時命令行中可能會出現編譯錯誤,比如頭文件找不到,函數找不到等等,細心找找就能改掉。
    編譯成功後,在工程目錄下libs/x86中就會生成你想要的.so庫。

    E. 有人編譯過android x86么

    應該可以直接安裝,但是運行不能保證成功,因為:如果你的APK是只編譯在ARM架構上的話,APK裡面的.so庫文件里(如果有),它是一些ARM指令,這肯定不能直接在Intel架構上運行。解決辦法:用NDK build android x86的.so庫(假設你有源代碼)。 1. 創建Application.mk文件,在文件中添加如下內容:(讓它生成x86下的庫文件) APP_ABI := armeabi armeabi-v7a x86 2. 如果不想使用Application.mk文件,則在ndk-build 參數中添加APP_ABI=「armeabi armeabi-v7a x86」 安裝APK時會根據系統cpu架構,將對應的.so庫文件復制到系統lib目錄。 當然還有一種裝虛擬機的辦法,讓APK在虛擬機裡面跑,但是這好像不是安裝到android系統。

    F. 在android中如何編譯連接 c 的可執行文件

    1. 在./development目錄下創建一目錄 如:myhello
    2. 進入hello目錄,在其下編寫自己的.c文件,如: myhello.c
    #include <stdio.h>
    int main()
    {
    printf("hello world\n");
    exit(0);
    //return 0;
    }
    3. 在hello目錄中,編寫Android.mk, 內容如下:
    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := myhelloworld
    LOCAL_SRC_FILES := myhello.c
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_EXECUTABLE)
    4. 回到Android源代碼頂層目錄,進行編譯,make myhelloworld
    5. 生成的可執行文件位於:out/target/proct/lotus/system/bin/ 目錄下
    6. adb push 到手機 /data 目錄下,然後進入adb shell,到data目錄下,執行./myhelloworld 皆可

    手動編譯連接【arm-eabi-gcc 的目錄隨andorid的版本而有變化,還有就是需要鏈接的文件如果比較多時,需要很多-l 就很麻煩了】
    7、編譯成目標文件:
    #$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -I bionic/libc/arch-arm/include/ -I bionic/libc/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -g -c helloworld.c -o hello.o
    8、生成可執行代碼:
    #$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,noreloc -o helloworld -Lout/target/proct/[generic]/obj/lib -Wl,-rpath-link=out/target/proct/[generic]/obj/lib -lc hello.o -entry=main

    其中[ ]中部分根據實際情況修改

    **************************************************
    實驗:
    1. 建目錄(my Android)/development/test, 在該目錄下新建 Android.mk和fb_test.c文件

    2. Android.mk文件

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := myfbtest
    LOCAL_SRC_FILES := fb_test.c
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_EXECUTABLE)

    3. 以下為fb_test.c
    #include <fcntl.h>
    #include <linux/fb.h>
    #include <sys/mman.h>
    #include <linux/kd.h>

    #include <stdio.h>

    #define FBBIT_PER_PIXEL 32
    #define FBBIT_PIXEL_IMAGE 16
    #define PIXELS_WIDTH_BYTE 4
    #define BYTE_PER_PIXEL 3
    #define FB_GRAPHICS_PATH "/dev/graphics/fb0"
    #define DEV_TTY0_PATH "/dev/tty0"

    #define DISPLAY_ERROR -1
    #define DISPLAY_SUCCESS 0

    #define GET_BATTERYCAPACITY_ERR -1

    #define MAX_STR 255

    static struct {
    int fd;
    void *pixels;
    struct fb_fix_screeninfo fixed;
    struct fb_var_screeninfo var;
    int align_xres;
    } fb;

    int getBatteryCapacity(void)
    {
    FILE *in;
    char tmpStr[MAX_STR + 1];
    char capfile[] = "/sys/class/power_supply/battery/capacity";

    if (capfile == NULL)
    return GET_BATTERYCAPACITY_ERR;

    in = fopen(capfile, "rt");
    if (in == NULL)
    return GET_BATTERYCAPACITY_ERR;

    if (fgets(tmpStr, MAX_STR, in) == NULL) {
    printf("Failed to read battery capacity!\n");
    fclose(in);
    return GET_BATTERYCAPACITY_ERR;

    }

    printf("Battery capacity(ascii): %s\n", tmpStr);
    fclose(in);

    return 0;//atoi(tmpStr);
    }

    static int vt_set_graphicsmode(int graphics)
    {
    int fd, r;
    fd = open(DEV_TTY0_PATH, O_RDWR | O_SYNC);
    if (fd < 0)
    return DISPLAY_ERROR;
    r = ioctl(fd, KDSETMODE, graphics);
    close(fd);
    return r;
    }

    int display_init(void)
    {
    fb.fd = open(FB_GRAPHICS_PATH, O_RDWR);
    if (fb.fd < 0)
    return DISPLAY_ERROR;

    if (ioctl(fb.fd, FBIOGET_FSCREENINFO, &fb.fixed) < 0)
    return DISPLAY_ERROR;
    if (ioctl(fb.fd, FBIOGET_VSCREENINFO, &fb.var) < 0)
    return DISPLAY_ERROR;
    fb.align_xres = fb.fixed.line_length /
    (fb.var.bits_per_pixel >> BYTE_PER_PIXEL);

    fb.pixels = mmap(0, fb.fixed.line_length * fb.var.yres_virtual,
    PROT_READ | PROT_WRITE, MAP_SHARED, fb.fd, 0);
    if (fb.pixels == MAP_FAILED)
    return DISPLAY_ERROR;

    vt_set_graphicsmode(KD_GRAPHICS);

    memset(fb.pixels, 0, fb.fixed.line_length * fb.var.yres_virtual);
    //display_update(fb.pixels, fb.align_xres, fb.var.yres);
    fb.var.activate = FB_ACTIVATE_FORCE;
    ioctl(fb.fd, FBIOPUT_VSCREENINFO, &fb.var);

    printf("display_init ok\n");

    return DISPLAY_SUCCESS;
    }

    void display_on(void)
    {
    ioctl(fb.fd, FBIOBLANK, FB_BLANK_UNBLANK);
    }

    void display_off(void)
    {
    ioctl(fb.fd, FBIOBLANK, FB_BLANK_POWERDOWN);
    }

    int main()
    {
    display_init();
    display_off();//關顯示屏

    getBatteryCapacity();
    sleep(5);

    display_on();//開顯示屏

    return 0;
    }

    G. x86上的android:性能與兼容可否兼得

    大部分Android應用都使用基於Dalvik Java代碼開發。理論上,由於Dalvik代碼在系統的虛擬機中執行,在x86的ATOM平台上不會有性能損失。但由於虛擬機執行效率的有限,對於一些高性能追求的應用,谷歌允許開發者使用原生的C語言代碼。而原生代碼是針對硬體平台編譯,x86,ARM或是MIPS都有其相應的二進制文件。通常來說,針對ARM平台編譯的二進制代碼,x86的處理器是無法直接運行的。而主流的安卓產品均採用ARM處理器,盡管很早之前,Google的Android NDK就引入了x86編譯的選項,但至今還是有相當一部分應用只針對ARM平台進行了編譯,這就造成了x86安卓平台兼容性問題。
    為了解決這一問題,Intel在推出Android手機系統的ATOM平台之初,就引入了「二進制轉換」(Binary Translation)這一功能,來解決x86無法直接運行ARM庫的問題。針對ARM編譯的二進制代碼會被ATOM處理器翻譯成x86執行的代碼,從而運行包含為ARM編譯的原生代碼的應用。

    H. 怎麼編譯linux x86

    首先你需要設置一下emulator工具的目錄之類的,這個不細說了,
    要在.bashrc中新增環境變數,如下
    ANDROID_PRODUCT_OUT=~/android/out/target/proct/generic
    ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/bin
    這里是設置你的輸出文件的位置和bin工具目錄,不用多解釋吧?
    然後在命令行輸入:
    export PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};
    上面是導入了相關的配置,然後使之生效。
    source ~/.bashrc
    接著切換到輸出的system文件夾
    cd ~/android/out/target/proct/generic
    然後來創建模擬器
    emulator -system system.img -data userdata.img -ramdisk ramdisk.img
    如果你運氣夠好的話,也許現在已經在運行了,不過我運氣明顯不夠好。
    提示一:
    emulator: ERROR: You did not specify a virtual device name, and the system
    directory could not be found.
    If you are an Android SDK user, please use 『@<name>』 or 『-avd <name>』
    to start a given virtual device (see -help-avd for details).
    Otherwise, follow the instructions in -help-disk-images to start the emulator

    既然人家提示了,那就按照步驟走吧,輸入命令:
    emulator -help-avd
    接著提示如下:
    use 『-avd <name>』 to start the emulator program with a given Android
    Virtual Device (a.k.a. AVD), where <name> must correspond to the name
    of one of the existing AVDs available on your host machine.
    See -help-virtual-device to learn how to create/list/manage AVDs.
    As a special convenience, using 『@<name>』 is equivalent to using
    『-avd <name>』.
    跟著提示繼續走,輸入命令:
    emulator -help-virtual-device
    又是提示了:
    An Android Virtual Device (AVD) models a single virtual
    device running the Android platform that has, at least, its own
    kernel, system image and data partition.
    Only one emulator process can run a given AVD at a time, but
    you can create several AVDs and run them concurrently.
    You can invoke a given AVD at startup using either 『-avd <name>』
    or 『@<name>』, both forms being equivalent. For example, to launch
    the AVD named 『foo』, type:
    emulator @foo
    The 『android』 helper tool can be used to manage virtual devices.
    For example:
    android create avd -n <name> -t 1 # creates a new virtual device.
    android list avd # list all virtual devices available.
    Try 『android –help』 for more commands.
    Each AVD really corresponds to a content directory which stores
    persistent and writable disk images as well as configuration files.
    Each AVD must be created against an existing SDK platform or add-on.
    For more information on this topic, see -help-sdk-images.

    I. 怎麼使用Android源碼編譯c模塊生成可執行文件

    1. 在./development目錄下創建一目錄 如:myhello
    2. 進入hello目錄,在其下編寫自己的.c文件,如: myhello.c
    #include <stdio.h>
    int main()
    {
    printf("hello world\n");
    exit(0);
    //return 0;
    }
    3. 在hello目錄中,編寫Android.mk, 內容如下:
    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := myhelloworld
    LOCAL_SRC_FILES := myhello.c
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_EXECUTABLE)
    4. 回到Android源代碼頂層目錄,進行編譯,make myhelloworld
    5. 生成的可執行文件位於:out/target/proct/lotus/system/bin/ 目錄下
    6. adb push 到手機 /data 目錄下,然後進入adb shell,到data目錄下,執行./myhelloworld 皆可

    手動編譯連接【arm-eabi-gcc 的目錄隨andorid的版本而有變化,還有就是需要鏈接的文件如果比較多時,需要很多-l 就很麻煩了】
    7、編譯成目標文件:
    #$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -I bionic/libc/arch-arm/include/ -I bionic/libc/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -g -c helloworld.c -o hello.o
    8、生成可執行代碼:
    #$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,noreloc -o helloworld -Lout/target/proct/[generic]/obj/lib -Wl,-rpath-link=out/target/proct/[generic]/obj/lib -lc hello.o -entry=main

    其中[ ]中部分根據實際情況修改

    **************************************************
    實驗:
    1. 建目錄(my Android)/development/test, 在該目錄下新建 Android.mk和fb_test.c文件

    2. Android.mk文件

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := myfbtest
    LOCAL_SRC_FILES := fb_test.c
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_EXECUTABLE)

    3. 以下為fb_test.c
    #include <fcntl.h>
    #include <linux/fb.h>
    #include <sys/mman.h>
    #include <linux/kd.h>

    #include <stdio.h>

    #define FBBIT_PER_PIXEL 32
    #define FBBIT_PIXEL_IMAGE 16
    #define PIXELS_WIDTH_BYTE 4
    #define BYTE_PER_PIXEL 3
    #define FB_GRAPHICS_PATH "/dev/graphics/fb0"
    #define DEV_TTY0_PATH "/dev/tty0"

    #define DISPLAY_ERROR -1
    #define DISPLAY_SUCCESS 0

    #define GET_BATTERYCAPACITY_ERR -1

    #define MAX_STR 255

    static struct {
    int fd;
    void *pixels;
    struct fb_fix_screeninfo fixed;
    struct fb_var_screeninfo var;
    int align_xres;
    } fb;

    int getBatteryCapacity(void)
    {
    FILE *in;
    char tmpStr[MAX_STR + 1];
    char capfile[] = "/sys/class/power_supply/battery/capacity";

    if (capfile == NULL)
    return GET_BATTERYCAPACITY_ERR;

    in = fopen(capfile, "rt");
    if (in == NULL)
    return GET_BATTERYCAPACITY_ERR;

    if (fgets(tmpStr, MAX_STR, in) == NULL) {
    printf("Failed to read battery capacity!\n");
    fclose(in);
    return GET_BATTERYCAPACITY_ERR;

    }

    printf("Battery capacity(ascii): %s\n", tmpStr);
    fclose(in);

    return 0;//atoi(tmpStr);
    }

    static int vt_set_graphicsmode(int graphics)
    {
    int fd, r;
    fd = open(DEV_TTY0_PATH, O_RDWR | O_SYNC);
    if (fd < 0)
    return DISPLAY_ERROR;
    r = ioctl(fd, KDSETMODE, graphics);
    close(fd);
    return r;
    }

    int display_init(void)
    {
    fb.fd = open(FB_GRAPHICS_PATH, O_RDWR);
    if (fb.fd < 0)
    return DISPLAY_ERROR;

    if (ioctl(fb.fd, FBIOGET_FSCREENINFO, &fb.fixed) < 0)
    return DISPLAY_ERROR;
    if (ioctl(fb.fd, FBIOGET_VSCREENINFO, &fb.var) < 0)
    return DISPLAY_ERROR;
    fb.align_xres = fb.fixed.line_length /
    (fb.var.bits_per_pixel >> BYTE_PER_PIXEL);

    fb.pixels = mmap(0, fb.fixed.line_length * fb.var.yres_virtual,
    PROT_READ | PROT_WRITE, MAP_SHARED, fb.fd, 0);
    if (fb.pixels == MAP_FAILED)
    return DISPLAY_ERROR;

    vt_set_graphicsmode(KD_GRAPHICS);

    memset(fb.pixels, 0, fb.fixed.line_length * fb.var.yres_virtual);
    //display_update(fb.pixels, fb.align_xres, fb.var.yres);
    fb.var.activate = FB_ACTIVATE_FORCE;
    ioctl(fb.fd, FBIOPUT_VSCREENINFO, &fb.var);

    printf("display_init ok\n");

    return DISPLAY_SUCCESS;
    }

    void display_on(void)
    {
    ioctl(fb.fd, FBIOBLANK, FB_BLANK_UNBLANK);
    }

    void display_off(void)
    {
    ioctl(fb.fd, FBIOBLANK, FB_BLANK_POWERDOWN);
    }

    int main()
    {
    display_init();
    display_off();//關顯示屏

    getBatteryCapacity();
    sleep(5);

    display_on();//開顯示屏

    return 0;
    }

    J. 為什麼X86 架構可以運行 android

    我們所說的android是基於linux內核的,並加以擴展,增加了一些android常用的驅動。
    說白了,android就相當於linux的一個應用程序。linux在X86架構上運行是沒有問題的,android當然也就可以。

    閱讀全文

    與android代碼編譯x86相關的資料

    熱點內容
    ug命令視頻大全 瀏覽:610
    箱子裝貨物最小容量編程 瀏覽:99
    cad2014教程pdf 瀏覽:200
    怎麼遍歷伺服器同一類型的文件 瀏覽:436
    惠普戰66畫圖編程 瀏覽:806
    java面向對象作業 瀏覽:570
    cad插件製作加密狗 瀏覽:924
    cmd命令對話框 瀏覽:291
    安卓應用怎麼常駐 瀏覽:677
    安卓手機怎麼群發小費才不會被鎖 瀏覽:742
    相機文件夾設置 瀏覽:856
    centos7php怎麼用 瀏覽:119
    查看linux操作系統版本的命令 瀏覽:384
    收支預演算法怎麼做 瀏覽:876
    模板如何上傳到伺服器 瀏覽:372
    如何同步安卓信息到新ipad 瀏覽:365
    騰訊雲輕量伺服器流量警告 瀏覽:504
    u盤備份linux 瀏覽:121
    高壓縮比活塞 瀏覽:93
    壓縮彈簧標准件 瀏覽:26