Skip to content

Commit

Permalink
basic android support (WiP)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jul 2, 2024
1 parent 5979f9b commit 96e82f6
Show file tree
Hide file tree
Showing 50 changed files with 1,423 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cache

/external
/third_party
/third_party_android

node_modules
.temp
Expand Down
137 changes: 137 additions & 0 deletions android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# -------------------- VALUES TO CONFIGURE --------------------

include versions.mk

ifeq ($(V),)
HIDE=@
MAKE += --no-print-directory
endif
PWD := $(shell pwd)

# Path to Android NDK
# NDK version must match ndkVersion in app/build.gradle
NDK_PATH := /home/sreimers/Android/Sdk/ndk/$(shell grep ndkVersion app/android/app/build.gradle.kts | sed 's/[^0-9.]*//g')

# Android API level
API_LEVEL := 26


# Set default from following values: [armeabi-v7a, arm64-v8a, x86_64]
ANDROID_TARGET_ARCH := arm64-v8a

# -------------------- GENERATED VALUES --------------------

ifeq ($(ANDROID_TARGET_ARCH), armeabi-v7a)
TARGET := arm-linux-androideabi
CLANG_TARGET := armv7a-linux-androideabi
ARCH := arm
OPENSSL_ARCH := android-arm
MARCH := armv7-a
else
ifeq ($(ANDROID_TARGET_ARCH), arm64-v8a)
TARGET := aarch64-linux-android
CLANG_TARGET := $(TARGET)
ARCH := arm
OPENSSL_ARCH := android-arm64
MARCH := armv8-a
else
ifeq ($(ANDROID_TARGET_ARCH), x86_64)
TARGET := x86_64-linux-android
CLANG_TARGET := $(TARGET)
ARCH := x86
OPENSSL_ARCH := android-x86_64
MARCH := x86-64
else
exit 1
endif
endif
endif

PLATFORM := android-$(API_LEVEL)

OS := $(shell uname -s | tr "[A-Z]" "[a-z]")
ifeq ($(OS),linux)
HOST_OS := linux-x86_64
endif
ifeq ($(OS),darwin)
HOST_OS := darwin-x86_64
endif

# Toolchain and sysroot
TOOLCHAIN := $(NDK_PATH)/toolchains/llvm/prebuilt/$(HOST_OS)
CMAKE_TOOLCHAIN_FILE := $(NDK_PATH)/build/cmake/android.toolchain.cmake
SYSROOT := $(TOOLCHAIN)/sysroot
PKG_CONFIG_LIBDIR := $(NDK_PATH)/prebuilt/$(HOST_OS)/lib/pkgconfig

# Toolchain tools
PATH := $(TOOLCHAIN)/bin:${PATH}
AR := llvm-ar
AS := $(CLANG_TARGET)$(API_LEVEL)-clang
CC := $(CLANG_TARGET)$(API_LEVEL)-clang
CXX := $(CLANG_TARGET)$(API_LEVEL)-clang++
LD := ld.lld
RANLIB := llvm-ranlib
STRIP := llvm-strip

CMAKE_ANDROID_FLAGS := \
-DANDROID=ON \
-DANDROID_PLATFORM=$(API_LEVEL) \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=$(API_LEVEL) \
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) \
-DANDROID_ABI=$(ANDROID_TARGET_ARCH) \
-DCMAKE_ANDROID_ARCH_ABI=$(ANDROID_TARGET_ARCH) \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_CXX_COMPILER=$(CXX) \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release

THIRD_PARTY_ROOT := ${PWD}/third_party_android/${ANDROID_TARGET_ARCH}

default: all

.PHONY: third_party_dir
third_party_dir:
mkdir -p ${THIRD_PARTY_ROOT}/include
mkdir -p ${THIRD_PARTY_ROOT}/lib

.PHONY: openssl
openssl: third_party_dir
$(HIDE)cd third_party_android && \
wget ${OPENSSL_MIRROR}/openssl-${OPENSSL_VERSION}.tar.gz && \
tar -xzf openssl-${OPENSSL_VERSION}.tar.gz && \
cp -a openssl-${OPENSSL_VERSION} openssl
@rm -f third_party/openssl-${OPENSSL_VERSION}.tar.gz
$(HIDE)cd third_party_android/openssl && \
ANDROID_NDK_ROOT=$(NDK_PATH) \
./Configure $(OPENSSL_ARCH) no-shared no-tests \
-U__ANDROID_API__ -D__ANDROID_API__=$(API_LEVEL) && \
make -j build_libs && \
cp *.a ${THIRD_PARTY_ROOT}/lib && \
cp -a include/openssl ${THIRD_PARTY_ROOT}/include/

.PHONY: lmdb
lmdb: third_party_dir
$(HIDE)cd third_party_android && \
git clone https://github.com/LMDB/lmdb && \
cd lmdb/libraries/liblmdb && \
make CC=$(CC) -j && \
cp liblmdb.a ${THIRD_PARTY_ROOT}/lib/ && \
cp lmdb.h ${THIRD_PARTY_ROOT}/include/

.PHONY: opus
opus: third_party_dir
$(HIDE)cd third_party_android && \
wget ${OPUS_MIRROR}/opus-${OPUS_VERSION}.tar.gz && \
tar -xzf opus-${OPUS_VERSION}.tar.gz && \
mv opus-${OPUS_VERSION} opus
$(HIDE)cd third_party_android/opus && \
CC=$(CC) ./configure --host=${TARGET} --disable-shared --with-pic --enable-dred \
--enable-deep-plc --enable-osce && \
make -j && \
cp .libs/libopus.a ${THIRD_PARTY_ROOT}/lib/ && \
mkdir -p ${THIRD_PARTY_ROOT}/include/opus && \
cp include/*.h ${THIRD_PARTY_ROOT}/include/opus/

all: openssl lmdb opus
15 changes: 15 additions & 0 deletions app/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions app/android/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/android/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/android/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions app/android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions app/android/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/android/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/android/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96e82f6

Please sign in to comment.