lineageOS编译一个模拟器版本

继上次的lineageOS编译并在S4上安装成功后,这次打算再进一步。

调试并改写Android源码。总需要一个模拟器来供调试吧。不然每次编译一个再刷到真机去,然后再调试显然太麻烦了。

Google了一下,貌似XDA论坛和reddit上都说lineageOS不支持模拟器运行。我:???
运行lunch看了一下设备,显然有x86版本啊,这不还支持arm呢(avd里面的arm模拟器光开机我就花了半个多小时,着实不敢恭维)

# lunch

You're building on Linux

Lunch menu... pick a combo:
     1. full-eng
     2. lineage_a3xelte-userdebug
     3. lineage_a5xelte-userdebug
     4. lineage_a5y17lte-userdebug
     5. lineage_a7y17lte-userdebug
     6. lineage_Amber-userdebug
...
     91. lineage_zl1-userdebug
     92. lineage_arm-userdebug
     93. lineage_arm64-userdebug
     94. lineage_x86-userdebug
     95. lineage_x86_64-userdebug

Which would you like? [aosp_arm-eng] 94
Trying dependencies-only mode on a non-existing device tree?
...

然后输入序号后发现能正确配置,于是两板斧开始

breakfast lineage_x86-userdebug
brunch lineage_x86-userdebug

更新,上面两个选项编译出来都无法运行。经过三天的尝试和各种搜索,建议如下代码

export WITH_SU=true
export WITHOUT_CHECK_API=true
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx12G"
lunch aosp_x86-userdebug
make -j12
emulator

4.5更新
修补patch
对于16.0版本:
https://review.lineageos.org/c/LineageOS/android_vendor_lineage/+/256909
对于17.1版本:
https://review.lineageos.org/c/LineageOS/android_vendor_lineage/+/265299
先lunch完,然后m sdk_addon,最后编译完的在out/host/linux-x86/sdk_addon

export ANDROID_PRODUCT_OUT=/home/happy/Android/lineage/out/target/product/generic_x86
./emulator -avd pixel -system $ANDROID_PRODUCT_OUT/system.img -data $ANDROID_PRODUCT_OUT/userdata.img -ramdisk $ANDROID_PRODUCT_OUT/ramdisk.img -kernel /home/happy/Android/lineage/prebuilts/qemu-kernel/x86/kernel-qemu

设置模拟器目录

if [ -d "/android_source_path/prebuilts/android-emulator/linux-x86_64" ] ; then
    PATH="/android_source_path/prebuilts/android-emulator/linux-x86_64:$PATH"
fi

设置OUT目录

export ANDROID_PRODUCT_OUT=/android_source_path/out/target/product/emulatorx86

使用编译好的镜像启动(arm)

emulator64-arm -kernel ./prebuilts/qemu-kernel/arm64/kernel-qemu -sysdir $ANDROID_PRODUCT_OUT -system $ANDROID_PRODUCT_OUT/system.img -data $ANDROID_PRODUCT_OUT/userdata.img -ramdisk $ANDROID_PRODUCT_OUT/ramdisk.img

使用编译好的镜像启动(x86)

emulator64-x86 -kernel ./prebuilts/qemu-kernel/x86/kernel-qemu -sysdir $ANDROID_PRODUCT_OUT -system $ANDROID_PRODUCT_OUT/system.img -data $ANDROID_PRODUCT_OUT/userdata.img -ramdisk $ANDROID_PRODUCT_OUT/ramdisk.img

增加编译的内存大小

发现内存分配了12g但用的只有4g左右。Google后发现是JACK默认限制使用的内存太小(来源)(官方文档),所以先执行

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"

如果编译前没有执行上面export命令,编译出错后再执行export,需要用下面命令重启jack

out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server

增加root

LineageOS默认取消了ROOT,如果希望编译的ROM自带ROOT,需要加入环境变量

export WITH_SU=true

各种编译问题杂烩

[1/1] /home/happy/Android/lineage/out/soong/.minibootstrap/minibp /home/happy/Android/lineage/out/soong/.bootstrap/build.ninja
[55/56] glob prebuilts/ndk/stl.bp
[80/80] /home/happy/Android/lineage/out/soong/.bootstrap/bin/soong_build /home/happy/Android/lineage/out/soong/build.ninja
FAILED: /home/happy/Android/lineage/out/soong/build.ninja 
/home/happy/Android/lineage/out/soong/.bootstrap/bin/soong_build -t -l /home/happy/Android/lineage/out/.module_paths/Android.bp.list -b /home/happy/Android/lineage/out/soong -n /home/happy/Android/lineage/out -d /home/happy/Android/lineage/out/soong/build.ninja.d -o /home/happy/Android/lineage/out/soong/build.ninja Android.bp
error: vendor/lineage/build/soong/Android.bp:31:8: module "generated_kernel_includes": cmd: unknown variable '$(KERNEL_MAKE_FLAGS)'
ninja: build stopped: subcommand failed.
00:57:54 soong bootstrap failed with: exit status 1

https://github.com/LineageOS/android_prebuilts_lineage-sdk

ninja: no work to do.
ninja: no work to do.
No need to regenerate ninja file
No need to regenerate ninja file
ninja: error: 'prebuilts/lineage-sdk/api/.txt', needed by '/home/happy/Android/lineage/out/target/common/obj/PACKAGING/checkpublicapi-lineage-last-timestamp', missing and no known rule to make it
01:19:56 ninja failed with: exit status 1
export WITHOUT_CHECK_API=1
  • 启动emulator提示
emulator: WARNING: system partition size adjusted to match image file (2048 MB > 800 MB)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, xcb.

打开调试

export QT_DEBUG_PLUGINS=1

发现其实qt加载的lib目录不对

QFactoryLoader::QFactoryLoader() checking directory path "/home/happy/Android/lineage/prebuilts/android-emulator/linux-x86_64/platforms" ...
Cannot load library /home/happy/Android/lineage/prebuilts/android-emulator/linux-x86_64/lib64/qt/plugins/platforms/libqxcb.so: (libc++.so: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/happy/Android/lineage/prebuilts/android-emulator/linux-x86_64/lib64/qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/happy/Android/lineage/prebuilts/android-emulator/linux-x86_64/lib64/qt/plugins/platforms/libqxcb.so: (libc++.so: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, xcb.

更改lib加载目录

export LD_LIBRARY_PATH=/home/happy/Android/lineage/prebuilts/android-emulator/linux-x86_64/lib64/qt/lib/
  • 如果中途提示链接错误,只要把那个中间文件删除再make一遍即可。
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: /home/happy/Android/lineage/out/soong/.intermediates/art/runtime/libartd/linux_glibc_x86_static/obj/.intermediates/art/runtime/art_operator_srcs/gen/art/runtime/thread.operator_out.o:1:2: syntax error, unexpected INTEGER, expecting $end
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: /home/happy/Android/lineage/out/soong/.intermediates/art/runtime/libartd/linux_glibc_x86_static/obj/.intermediates/art/runtime/art_operator_srcs/gen/art/runtime/thread.operator_out.o: not an object or archive
clang: error: linker command failed with exit code 1 (use -v to see invocation)

然后我们删除这个文件即可

rm /home/happy/Android/lineage/out/soong/.intermediates/art/runtime/libartd/linux_glibc_x86_static/obj/.intermediates/art/runtime/art_operator_srcs/gen/art/runtime/thread.operator_out.o

杂烩

[1/1] /home/happy/Android/lineage/out/soong/.minibootstrap/minibp /home/happy/Android/lineage/out/soong/.bootstrap/build.ninja
[55/56] glob prebuilts/ndk/stl.bp
[80/80] /home/happy/Android/lineage/out/soong/.bootstrap/bin/soong_build /home/happy/Android/lineage/out/soong/build.ninja
FAILED: /home/happy/Android/lineage/out/soong/build.ninja 
/home/happy/Android/lineage/out/soong/.bootstrap/bin/soong_build -t -l /home/happy/Android/lineage/out/.module_paths/Android.bp.list -b /home/happy/Android/lineage/out/soong -n /home/happy/Android/lineage/out -d /home/happy/Android/lineage/out/soong/build.ninja.d -o /home/happy/Android/lineage/out/soong/build.ninja Android.bp
error: vendor/lineage/build/soong/Android.bp:31:8: module "generated_kernel_includes": cmd: unknown variable '$(KERNEL_MAKE_FLAGS)'
ninja: build stopped: subcommand failed.
00:57:54 soong bootstrap failed with: exit status 1

https://github.com/LineageOS/android_prebuilts_lineage-sdk

ninja: no work to do.
ninja: no work to do.
No need to regenerate ninja file
No need to regenerate ninja file
ninja: error: 'prebuilts/lineage-sdk/api/.txt', needed by '/home/happy/Android/lineage/out/target/common/obj/PACKAGING/checkpublicapi-lineage-last-timestamp', missing and no known rule to make it
01:19:56 ninja failed with: exit status 1
export WITHOUT_CHECK_API=true
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx12G"
lunch mini_emulator_x86-userdebug
emulator -partition-size 1024 -memory 2096

参考

https://www.cnblogs.com/luoyesiqiu/p/10701419.html

你可能感兴趣的:(lineageOS编译一个模拟器版本)