Docker+AOSP+GMS(OpenGApps)+Mac80211_hwsim+Hostapd+Dhcp+Wifi AOSP

mowen 2022-10-31 3700

Ubuntu 20.04
Disk>=300G
Mem>=16G
CPU>=8
sudo useradd -m mowen -s /bin/bash
sudo passwd mowen
sudo adduser mowen sudo
su mowen
sudo apt update

sudo apt-get install -y git curl

# More info: https://github.com/git-lfs/git-lfs/blob/master/INSTALLING.md
# Apt/deb
sudo apt install git-lfs

# Yum/rpm
sudo yum install git-lfs

# on macOS
brew install git-lfs

git config --global user.email "xxxx@xxx.com"

git config --global user.name "xxxx"

mkdir ~/bin

PATH=~/bin:$PATH

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

or

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo

chmod a+x ~/bin/repo

export REPO_URL='https://mirrors.ustc.edu.cn/aosp/git-repo'

or

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo

# 设置Windows主机aosp源码目录大小写敏感
fsutil.exe file setCaseSensitiveInfo h:\\AOSP\\aosp enable

# Linux编译机进入Windows主机aosp源码目录
cd /mnt/h/AOSP/aosp

python3 ~/bin/repo init -u android.googlesource.com/platform/manifest -b android-13.0.0_r24 --depth=1

or

# fetch remote-android branch
# redroid-9.0.0
# redroid-10.0.0
# redroid-11.0.0
# redroid-12.0.0
# redroid-13.0.0_r24
python3 ~/bin/repo init -u https://github.com/remote-android/platform_manifests.git -b redroid-13.0.0_r24 --depth=1

or

# using ustc mirror
python3 ~/bin/repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-13.0.0_r24 --depth=1

or

# using tsinghua mirror
# https://source.android.com/docs/setup/about/build-numbers?hl=zh-cn#source-code-tags-and-builds
python3 ~/bin/repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r24 --depth=1

or

# using tsinghua monthly archive
curl -OC - https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
tar xf aosp-latest.tar
cd AOSP

# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
# 正常同步一遍即可得到完整目录
python3 ~/bin/repo sync

or

python3 ~/bin/repo sync -c -f --no-tags --no-clone-bundle -j`nproc`

# 或仅checkout代码
python3 ~/bin/repo sync -l

# sync
python3 ~/bin/repo sync -c -j12

# 查看aosp远程分支
git --git-dir=.repo/manifests/.git/ branch -rv

# 查看aosp本地分支
git --git-dir=.repo/manifests/.git/ branch -vv

# 切换aosp本地分支
python3 ~/bin/repo init -b gingerbread-release

# 本地分支问题重置
python3 ~/bin/repo forall -c git reset --hard remotes/origin/xxxxxxx
python3 ~/bin/repo forall -c git xxxxxxx
python3 ~/bin/repo sync

<OpenGApps>

# use normal user to install docker
su mowen

sudo snap install docker

# create builder docker image
sudo docker build --build-arg userid=$(id -u) --build-arg groupid=$(id -g) --build-arg username=$(id -un) -t redroid-builder .

# start builder
sudo docker run -it --rm --hostname redroid-builder --name redroid-builder -v /root:/src redroid-builder

# *inside* builder container
cd /src

. build/envsetup.sh

lunch redroid_x86_64-userdebug
# lunch redroid_arm64-userdebug
# lunch redroid_x86_64_only-userdebug (64 bit only, redroid 12+)
# lunch redroid_arm64_only-userdebug (64 bit only, redroid 12+)

make clobber && make

# create redroid docker image in *HOST*
cd <BUILD-OUT-DIR>
sudo mount system.img system -o ro &&
sudo mount vendor.img vendor -o ro &&
sudo tar --xattrs -c vendor -C system --exclude="vendor" . | docker import -c 'ENTRYPOINT ["/init", "qemu=1", "androidboot.hardware=redroid"]' - mowen99/redroid-gms:11.0.0-amd64 &&
sudo umount system &&
sudo umount vendor

# create rootfs only image for develop purpose
tar --xattrs -c -C root . | docker import -c 'ENTRYPOINT ["/init", "qemu=1", "androidboot.hardware=redroid"]' - redroid-dev

# load kernel modules
apt install linux-modules-extra-`uname -r` &&
modprobe binder_linux devices="binder,hwbinder,vndbinder" &&
modprobe ashmem_linux &&
lsmod|grep -e ashmem -e binder

# run container
docker run -itd --memory-swappiness=0 --name redroid --restart always --privileged -v ~/data11:/data -p 6666:5555 mowen99/redroid-gms:11.0.0-amd64 &&
docker exec -it redroid pm -l

# remove container
docker stop redroid && docker rm redroid && rm -rf ~/data11


Kernel

mkdir /opt/kernel && cd /opt/kernel &&
python3 ~/bin/repo init -u https://android.googlesource.com/kernel/manifest -b common-android-4.19-stable &&
python3 ~/bin/repo sync -c -j8


Wpa_supplicant

https://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf
https://android.googlesource.com/platform/hardware/broadcom/wlan
https://android.googlesource.com/platform/external/wpa_supplicant_8
TARGET_PRODUCT_KERNEL_HEADERS += device/redroid/include

# WiFi required by SystemUI
PRODUCT_PACKAGES += \
    android.hardware.wifi@1.0-service \
    android.hardware.wifi.supplicant@1.0::ISupplicant \
    mac80211_create_radios \
    lib_driver_cmd_simulated \
    libwifi-hal-emu \
    createns \
    dhcpclient \
    execns \
    hostapd \
    hostapd_nohidl \
    netmgr \
    wifi_forwarder \
    wpa_supplicant \
    libwpa_client \
    wifilogd \
    wificond \

PRODUCT_COPY_FILE += \
    device/generic/goldfish/data/etc/apns-conf.xml:data/misc/apns/apns-conf.xml \
    device/generic/goldfish/radio/RadioConfig/radioconfig.xml:data/misc/emulator/config/radioconfig.xml \
    device/generic/goldfish/wifi/init.wifi.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.wifi.sh \
    device/generic/goldfish/wifi/simulated_hostapd.conf:$(TARGET_COPY_OUT_VENDOR)/etc/simulated_hostapd.conf \
    #device/generic/goldfish/wifi/wpa_supplicant.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant.conf \
    device/generic/goldfish/wifi/WifiConfigStore.xml:data/misc/wifi/WifiConfigStore.xml \
    frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml \
    frameworks/native/data/etc/android.hardware.wifi.passpoint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.passpoint.xml \
    frameworks/native/data/etc/android.hardware.wifi.direct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.direct.xml \
    frameworks/native/data/etc/android.hardware.bluetooth_le.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth_le.xml \
    frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \
/root/device/redroid/redroid_x86_64/BoardConfig.mk

WPA_SUPPLICANT_VERSION := VER_0_8_X
BOARD_WLAN_DEVICE := bcmdhd
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
WIFI_DRIVER_MODULE_NAME := "bcmdhd"
WIFI_DRIVER_MODULE_PATH := "/system/lib/modules/bcmdhd.ko"
WIFI_HIDL_FEATURE_DUAL_INTERFACE := true

mmm hardware/broadcom/wlan/bcmdhd/wpa_supplicant_8_lib
external/wpa_supplicant_8/Android.mk

$(LOCAL_PATH)/wpa_supplicant/Android.mk // modify this about line 9
external/wpa_supplicant_8/src/utils/wpa_debug.c

int wpa_debug_level = MSG_DEBUG; // modify this about line 30
external/wpa_supplicant_8/wpa_supplicant/android.config

# CONFIG_DRIVER_WEXT=y // modify this about line 29
CONFIG_DRIVER_NL80211=y // open this about line 32
CONFIG_LIBNL20=y // open this about line 3

mmm external/wpa_supplicant_8


Mac80211_hwsim

# https://wireless.wiki.kernel.org/en/users/drivers/mac80211_hwsim
# https://www.kernel.org/doc/html/latest/networking/mac80211_hwsim/mac80211_hwsim.html

# Build mac80211_hwsim as part of kernel configuration
...

# Load the module
modprobe mac80211_hwsim

# Run hostapd (AP) for wlan0
...

# Run wpa_supplicant (station) for wlan1
...


Udhcpd

apt-get install -y udhcpd

/etc/udhcpd.conf

interface       wlan0           #default: eth0 // modity this line about line 11 eth0 -> wlanX

systemctl start udhcpd && systemctl enable udhcpd && systemctl status udhcpd


Hostapd

apt-get install -y hostapd

/etc/hostapd/hostapd.conf

ctrl_interface=/var/run/hostapd
nterface=wlan0
driver=nl80211
ieee80211n=1
hw_mode=g
channel=6
ssid="CCSSID"
wpa=2
wpa_passphrase="a12345678A"
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP TKIP
wpa_pairwise=TKIP CCMP

service hostapd stop &&
ifconfig wlan0 192.168.0.20 &&
hostapd /etc/hostapd/hostapd.conf -td &&
iptables -A FORWARD -i wlan0 -o eth0 -s 192.168.0.0/24 -m state --state NEW -j ACCEPT &&
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT &&
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE &&
echo "1" >/proc/sys/net/ipv4/ip_forward &&
wpa_cli -iwlan1 -p/data/misc/wifi/wlan0


Wifi

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

<bool name="def_wifi_display_on">true</bool> // modify this line about line 40
<bool name="def_install_non_market_apps">true</bool> // modify this line about line 41
<bool name="def_wifi_on">true</bool> // modify this line about line 47
<integer name="def_wifi_sleep_policy">0</integer> // modify this line about line 49
<bool name="def_wifi_wakeup_enabled">true</bool> // modify this line about line 50
<integer name="def_wifi_scan_always_available">1</integer> // modify this line about line 160

<bool name="def_user_setup_complete">true</bool> // modify this line about line 146
mkdir /var/run/wpa_supplicant

out/target/product/redroid_x86_64/system/etc/wifi/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
update_config=1
eapol_version=1
ap_scan=1
fast_reauth=1

network={
        ssid="CCSSID"
        psk="a12345678A"
        key_mgmt=WPA-PSK
}

wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211 -ddd -iwlan1


OpenGApps

.repo/manifests/opengapps.xml

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
	<remote name="opengapps" fetch="https://github.com/opengapps/"  />
	<remote name="opengapps-gitlab" fetch="https://gitlab.opengapps.org/opengapps/"  />
	<project path="vendor/opengapps/build" name="aosp_build" revision="master" remote="opengapps" />
	<project path="vendor/opengapps/sources/all" name="all" clone-depth="1" revision="master" remote="opengapps-gitlab" />
	<!-- arm64 depends on arm -->
	<project path="vendor/opengapps/sources/arm" name="arm" clone-depth="1" revision="master" remote="opengapps-gitlab" />
	<project path="vendor/opengapps/sources/arm64" name="arm64" clone-depth="1" revision="master" remote="opengapps-gitlab" />
	<project path="vendor/opengapps/sources/x86" name="x86" clone-depth="1" revision="master" remote="opengapps-gitlab" />
	<project path="vendor/opengapps/sources/x86_64" name="x86_64" clone-depth="1" revision="master" remote="opengapps-gitlab" />
</manifest>
.repo/manifests/redroid.xml

<include name="opengapps.xml" />
device/redroid/redroid_x86_64/device.mk

GAPPS_VARIANT := stock
GAPPS_EXCLUDED_PACKAGES += GoogleCamera
PRODUCT_COPY_FILES += device/redroid/mediacodec.policy.x86:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediacodec.policy \
$(call inherit-product, vendor/opengapps/build/opengapps-packages.mk)
$(call inherit-product, device/redroid-prebuilts/prebuilts_x86.mk)

device/redroid/redroid_arm64/device.mk

GAPPS_VARIANT := stock
GAPPS_EXCLUDED_PACKAGES += GoogleCamera
PRODUCT_COPY_FILES += device/redroid/mediacodec.policy.arm:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediacodec.policy \
$(call inherit-product, vendor/opengapps/build/opengapps-packages.mk)
$(call inherit-product, device/redroid-prebuilts/prebuilts_arm.mk)
python3 ~/bin/repo sync -c -j8
vendor/opengapps/build/modules/Android.mk

include $(call all-named-subdir-makefiles,$(GAPPS_PRODUCT_PACKAGES))
vendor/opengapps/build/opengapps-packages.mk

ifneq ($(filter 28,$(call get-allowed-api-levels)),)
GAPPS_PRODUCT_PACKAGES += \
    DigitalWellbeing \
    MarkupGoogle \    // remove this line about line 112
    SoundPicker
endif

...

GAPPS_FORCE_MMS_OVERRIDES := true
GAPPS_FORCE_WEBVIEW_OVERRIDES := true
GAPPS_PRODUCT_PACKAGES += \
    GoogleCamera \     // remove this line about line 165
    GoogleContacts \
    LatinImeGoogle \
    StorageManagerGoogle \
cd vendor/opengapps/sources

git-lfs install

python3 ~/bin/repo forall -c git lfs pull

git clone https://gitlab.opengapps.org/opengapps/all.git
git clone https://gitlab.opengapps.org/opengapps/arm.git
git clone https://gitlab.opengapps.org/opengapps/arm64.git
git clone https://gitlab.opengapps.org/opengapps/x86.git
git clone https://gitlab.opengapps.org/opengapps/x86_64.git

Or

# FAILED: out/target/product/redroid_x86_64/obj/APPS/CalculatorGoogle_intermediates/package.apk
# Unable to open 'out/target/product/redroid_x86_64/obj/APPS/CalculatorGoogle_intermediates/package.apk' for verification
# Unable to open 'out/target/product/redroid_x86_64/obj/APPS/CalculatorGoogle_intermediates/package.apk.unaligned' as zip archive
# mv: bad 'out/target/product/redroid_x86_64/obj/APPS/CalculatorGoogle_intermediates/package.apk.aligned': No such file or directory
python3 ~/bin/repo forall -r '.*opengapps.*' -c 'git lfs fetch && git lfs checkout'
Error && fixed

[  0% 11/18898] Check prebuilt ELF binary: vendor/opengapps/sources/x86_64/lib64/23/libjni_latinimegoogle.so
FAILED: out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp
/bin/bash -c "(rm -f out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp ) && (build/make/tools/check_elf_file.py          --skip-bad-elf-magic            --skip-unknown-elf-machine      --soname libjni_latinimegoogle.so       --shared-lib out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libstdc++_intermediates/libstdc++.so --shared-lib out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libc++_intermediates/libc++.so --shared-lib out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libc_intermediates/libc.so --shared-lib out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libm_intermediates/libm.so --shared-lib out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libdl_intermediates/libdl.so                  --llvm-readobj=prebuilts/clang/host/linux-x86/clang-r383902b1/bin/llvm-readobj          vendor/opengapps/sources/x86_64/lib64/23/libjni_latinimegoogle.so ) && (touch out/target/product/redroid_x86_64/obj/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp )"
vendor/opengapps/sources/x86_64/lib64/23/libjni_latinimegoogle.so: error: DT_SONAME "libjni_unbundled_latinimegoogle.so" must be equal to the file name "libjni_latinimegoogle.so".

[  0% 12/18898] Check prebuilt ELF binary: vendor/opengapps/sources/x86/lib/23/libjni_latinimegoogle.so
FAILED: out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp
/bin/bash -c "(rm -f out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp ) && (build/make/tools/check_elf_file.py      --skip-bad-elf-magic            --skip-unknown-elf-machine      --soname libjni_latinimegoogle.so       --shared-lib out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libstdc++_intermediates/libstdc++.so --shared-lib out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libc++_intermediates/libc++.so --shared-lib out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libc_intermediates/libc.so --shared-lib out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libm_intermediates/libm.so --shared-lib out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libdl_intermediates/libdl.so              --llvm-readobj=prebuilts/clang/host/linux-x86/clang-r383902b1/bin/llvm-readobj          vendor/opengapps/sources/x86/lib/23/libjni_latinimegoogle.so ) && (touch out/target/product/redroid_x86_64/obj_x86/SHARED_LIBRARIES/libjni_latinimegoogle_intermediates/check_elf_files.timestamp )"
vendor/opengapps/sources/x86/lib/23/libjni_latinimegoogle.so: error: DT_SONAME "libjni_unbundled_latinimegoogle.so" must be equal to the file name "libjni_latinimegoogle.so".

vim vendor/opengapps/build/modules/LatinImeGoogle/Android.mk

LOCAL_REQUIRED_MODULES := libjni_unbundled_latinimegoogle // update this line
LOCAL_MODULE := libjni_unbundled_latinimegoogle.so // update this line
error: RPC failed; curl 56 GnuTLS recv error (-9): Error decoding the received TLS packet.

sudo apt install gnutls-bin
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000 //增加至1GB缓存
fatal: detected dubious ownership in repository at

git config --global --add safe.directory "*";


ROM Registry

adb root

adb shell 'sqlite3 /data/data/com.google.android.gsf/databases/gservices.db "select * from main where name = \"android_id\";"'
    
android_id|4560257781094180552

https://www.google.com/android/uncertified/


Dockfile

FROM ubuntu:20.04
 
ARG userid
ARG groupid
ARG username
 
# COPY apt.conf /etc/apt/apt.conf
 
# COPY sources.list etc/apt/sources.list
 
ENV DEBIAN_FRONTEND noninteractive
 
RUN apt-get update \
    && echo "install package for building AOSP" \
    && apt-get install -y git-core gnupg flex bison build-essential zip curl zlib1g-dev \
        gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev \
        libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig \
        rsync python3-pip pkg-config python3-dev ninja-build \
    && pip3 install mako meson \
    && apt-get install -y python2 python-mako python-is-python2 python-enum34 gettext \
    && apt-get install -y dialog apt-utils linux-headers-`uname -r`
 
 
RUN groupadd -g $groupid $username \
    && useradd -m -u $userid -g $groupid $username \
    && echo "$username ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
    && echo $username >/root/username \
    && echo "$username:$username" | chpasswd && adduser $username sudo
 
 
ENV HOME=/home/$username \
    USER=$username \
    PATH=/src/.repo/repo:/src/prebuilts/jdk/jdk8/linux-x86/bin/:$PATH
 
 
ENTRYPOINT chroot --userspec=$(cat /root/username):$(cat /root/username) / /bin/bash -i
上传的附件:
最新回复 (0)
返回
发新帖
X