导航:首页 > 源码编译 > 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相关的资料

    热点内容
    什么app看本子 浏览:394
    如何学好编译语言 浏览:591
    平面编程和切削 浏览:704
    phpemoji表情符号 浏览:778
    IBM云平台shor算法 浏览:576
    程序员当乙方 浏览:519
    php商城设计与实现的 浏览:305
    php自动打印 浏览:469
    哪个app多年轻人 浏览:902
    租的服务器如何重装 浏览:937
    干眼症程序员 浏览:239
    乐动达人安卓版有什么游戏 浏览:484
    c523压缩比 浏览:543
    命令语气的人什么心态 浏览:435
    程序员喜欢留指甲吗 浏览:516
    七牛云服务器收费标准 浏览:627
    时光相册加密空间密码忘记 浏览:474
    华为云为用户提供的服务云服务器 浏览:634
    minecraftlinux服务器搭建 浏览:377
    linux命令新建文件 浏览:709