Skip to content

Commit c09707a

Browse files
committed
Init
0 parents  commit c09707a

40 files changed

+1655
-0
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build aapt2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
workflow_dispatch:
9+
inputs:
10+
logLevel:
11+
description: 'Reason'
12+
required: false
13+
default: 'Update package'
14+
15+
jobs:
16+
build:
17+
name: build
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
target_arch: [x86_64, x86, arm64-v8a, armeabi-v7a]
22+
fail-fast: false
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
with:
27+
submodules: 'true'
28+
29+
- uses: nttld/setup-ndk@v1
30+
id: setup-ndk
31+
with:
32+
ndk-version: r23c
33+
add-to-path: false
34+
- run: ./build.sh ${{ matrix.target_arch }}
35+
env:
36+
NDK_TOOLCHAIN: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64
37+
38+
- name: Upload artifacts
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: dist-${{ matrix.target_arch }}
42+
path: dist

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
build/

.gitmodules

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[submodule "src/expat"]
2+
shallow = true
3+
path = src/expat
4+
url = https://android.googlesource.com/platform/external/expat.git
5+
[submodule "src/fmtlib"]
6+
shallow = true
7+
path = src/fmtlib
8+
url = https://android.googlesource.com/platform/external/fmtlib.git
9+
[submodule "src/boringssl"]
10+
shallow = true
11+
path = src/boringssl
12+
url = https://boringssl.googlesource.com/boringssl.git
13+
[submodule "src/incremental_delivery"]
14+
shallow = true
15+
path = src/incremental_delivery
16+
url = https://android.googlesource.com/platform/system/incremental_delivery
17+
[submodule "src/libbase"]
18+
shallow = true
19+
path = src/libbase
20+
url = https://android.googlesource.com/platform/system/libbase
21+
[submodule "src/libpng"]
22+
shallow = true
23+
path = src/libpng
24+
url = https://android.googlesource.com/platform/external/libpng.git
25+
[submodule "src/pcre"]
26+
shallow = true
27+
path = src/pcre
28+
url = https://android.googlesource.com/platform/external/pcre.git
29+
[submodule "src/zopfli"]
30+
shallow = true
31+
path = src/zopfli
32+
url = https://android.googlesource.com/platform/external/zopfli
33+
[submodule "src/protobuf"]
34+
shallow = true
35+
path = src/protobuf
36+
url = https://android.googlesource.com/platform/external/protobuf
37+
[submodule "src/logging"]
38+
shallow = true
39+
path = src/logging
40+
url = https://android.googlesource.com/platform/system/logging.git
41+
[submodule "src/selinux"]
42+
shallow = true
43+
path = src/selinux
44+
url = https://android.googlesource.com/platform/external/selinux.git
45+
[submodule "src/core"]
46+
shallow = true
47+
path = src/core
48+
url = https://android.googlesource.com/platform/system/core.git
49+
[submodule "src/base"]
50+
shallow = true
51+
path = src/base
52+
url = https://android.googlesource.com/platform/frameworks/base
53+
[submodule "src/libziparchive"]
54+
shallow = true
55+
path = src/libziparchive
56+
url = https://android.googlesource.com/platform/system/libziparchive

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.14.2)
2+
project(sdk-tools)
3+
4+
if(ANDROID_ABI STREQUAL "arm64-v8a" OR ANDROID_ABI STREQUAL "armeabi-v7a")
5+
enable_language(ASM)
6+
elseif(ANDROID_ABI STREQUAL "x86_64" OR ANDROID_ABI STREQUAL "x86")
7+
enable_language(ASM_NASM)
8+
else()
9+
message(FATAL_ERROR "Unsupported architecture: ${ANDROID_ABI}")
10+
endif()
11+
12+
# set global cflags and cxxflags
13+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics -fPIC -Wno-attributes -std=gnu11")
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics -fPIC -Wno-attributes -std=gnu++2a")
15+
# static link
16+
set(CMAKE_EXE_LINKER_FLAGS "-static")
17+
18+
# platform tools version
19+
# see the patches/other/platform_tools_version.h
20+
set(TOOLS_VERSION 33.0.1)
21+
set(SRC ${PROJECT_SOURCE_DIR}/src)
22+
23+
# 64-bit off_t for lseek.
24+
add_definitions(-D_FILE_OFFSET_BITS=64)
25+
26+
if(NOT DEFINED PROTOC_PATH)
27+
message(FATAL_ERROR "PROTOC_PATH undefined, please make sure to build and install protoc from the cloned submodule." )
28+
endif()
29+
30+
set(PROTOC_COMPILER ${PROTOC_PATH})
31+
32+
if(NOT EXISTS ${PROTOC_COMPILER})
33+
unset(PROTOC_PATH CACHE)
34+
message(FATAL_ERROR "Invalid protoc: ${PROTOC_COMPILER}, please check if the path is correct")
35+
endif()
36+
37+
# thrid-party libraries
38+
add_subdirectory(src/boringssl EXCLUDE_FROM_ALL)
39+
add_subdirectory(src/fmtlib EXCLUDE_FROM_ALL)
40+
add_subdirectory(src/pcre EXCLUDE_FROM_ALL)
41+
add_subdirectory(src/expat EXCLUDE_FROM_ALL)
42+
add_subdirectory(src/zopfli EXCLUDE_FROM_ALL)
43+
add_subdirectory(src/protobuf/cmake EXCLUDE_FROM_ALL)
44+
45+
# building sdk-tools
46+
add_subdirectory(cmake)

build.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
# Check for NDK_TOOLCHAIN environment variable and abort if it is not set.
4+
if [[ -z "${NDK_TOOLCHAIN}" ]]; then
5+
echo "Please specify the Android NDK environment variable \"NDK_TOOLCHAIN\"."
6+
exit 1
7+
fi
8+
9+
# Prerequisites.
10+
sudo apt install \
11+
golang \
12+
ninja-build \
13+
autogen \
14+
autoconf \
15+
libtool \
16+
build-essential \
17+
-y || exit 1
18+
19+
root="$(pwd)"
20+
21+
# Install protobuf compiler.
22+
cd "src/protobuf" || exit 1
23+
./autogen.sh
24+
./configure
25+
make -j"$(nproc)"
26+
sudo make install
27+
sudo ldconfig
28+
29+
# Go back.
30+
cd "$root" || exit 1
31+
32+
# Apply patches.
33+
git apply patches/incremental_delivery.patch --whitespace=fix
34+
git apply patches/libpng.patch --whitespace=fix
35+
git apply patches/selinux.patch --whitespace=fix
36+
git apply patches/protobuf.patch --whitespace=fix
37+
git apply patches/aapt2.patch --whitespace=fix
38+
git apply patches/boringssl.patch --whitespace=fix
39+
40+
# Define all the compilers, libraries and targets.
41+
api="30"
42+
architecture=$1
43+
declare -A compilers=(
44+
[x86_64]=x86_64-linux-android
45+
[x86]=i686-linux-android
46+
[arm64-v8a]=aarch64-linux-android
47+
[armeabi-v7a]=armv7a-linux-androideabi
48+
)
49+
declare -A lib_arch=(
50+
[x86_64]=x86_64-linux-android
51+
[x86]=i686-linux-android
52+
[arm64-v8a]=aarch64-linux-android
53+
[armeabi-v7a]=arm-linux-androideabi
54+
)
55+
declare -A target_abi=(
56+
[x86_64]=x86_64
57+
[x86]=x86
58+
[arm64-v8a]=aarch64
59+
[armeabi-v7a]=arm
60+
)
61+
62+
build_directory="build"
63+
aapt_binary_path="$root/$build_directory/cmake/aapt2"
64+
# Build all the target architectures.
65+
bin_directory="$root/dist/$architecture"
66+
67+
# switch to cmake build directory.
68+
[[ -d dir ]] || mkdir -p $build_directory && cd $build_directory || exit 1
69+
70+
# Define the compiler architecture and compiler.
71+
compiler_arch="${compilers[$architecture]}"
72+
c_compiler="$compiler_arch$api-clang"
73+
cxx_compiler="${c_compiler}++"
74+
75+
# Copy libc.a to libpthread.a.
76+
lib_path="$NDK_TOOLCHAIN/sysroot/usr/lib/${lib_arch[$architecture]}/$api/"
77+
cp -n "$lib_path/libc.a" "$lib_path/libpthread.a"
78+
79+
# Run make for the target architecture.
80+
compiler_bin_directory="$NDK_TOOLCHAIN/bin/"
81+
cmake -GNinja \
82+
-DCMAKE_C_COMPILER="$compiler_bin_directory$c_compiler" \
83+
-DCMAKE_CXX_COMPILER="$compiler_bin_directory$cxx_compiler" \
84+
-DCMAKE_BUILD_WITH_INSTALL_RPATH=True \
85+
-DCMAKE_BUILD_TYPE=Release \
86+
-DANDROID_ABI="$architecture" \
87+
-DTARGET_ABI="${target_abi[$architecture]}" \
88+
-DPROTOC_PATH="/usr/local/bin/protoc" \
89+
-DCMAKE_SYSROOT="$NDK_TOOLCHAIN/sysroot" \
90+
.. || exit 1
91+
92+
ninja || exit 1
93+
94+
"$NDK_TOOLCHAIN/bin/llvm-strip" --strip-unneeded "$aapt_binary_path"
95+
96+
# Create bin directory.
97+
mkdir -p "$bin_directory"
98+
99+
# Move aapt2 to bin directory.
100+
mv "$aapt_binary_path" "$bin_directory"

cmake/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include(libbase.cmake)
2+
include(liblog.cmake)
3+
include(libcutils.cmake)
4+
include(libutils.cmake)
5+
include(libpackagelistparser.cmake)
6+
include(libandroidfw.cmake)
7+
include(libincfs.cmake)
8+
include(libselinux.cmake)
9+
include(libsepol.cmake)
10+
include(libpng.cmake)
11+
include(libsparse.cmake)
12+
include(libziparchive.cmake)
13+
include(aapt2.cmake)

0 commit comments

Comments
 (0)