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

mowen 2022-10-31 419

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://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo

chmod a+x ~/bin/repo

# use CCACHE
export USE_CCACHE=1
export CCACHE_EXEC=/opt/ccache
ccache -M 50G
ccache -o compression=true

# fetch code
python3 ~/bin/repo init -u https://github.com/remote-android/platform_manifests.git -b android-11.0.0_r48 --depth=1

or

python3 ~/bin/repo init -u https://github.com/remote-android/platform_manifests.git -b redroid-11.0.0 --depth=1

python3 ~/bin/repo sync -c -j8

<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


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 \
        dialog apt-utils linux-headers-`uname -r`\
    && echo "install utils" \
    && apt-get install -y sudo rsync \
    && echo "install packages for build mesa3d or meson related" \
    && apt-get install -y python3-pip pkg-config python3-dev ninja-build \
    && pip3 install mako meson \
    && echo "packages for legacy mesa3d (< 22.0.0)" \
    && apt-get install -y python2 python-mako python-is-python2 python-enum34 gettext
 
 
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