Skip to content

Commit

Permalink
Android support (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
phnzb authored Aug 1, 2024
1 parent c5dce75 commit 7f8360c
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 89 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: android build

on:
workflow_call:
workflow_dispatch:

jobs:
build:
runs-on: [self-hosted, nzbget-android]

steps:

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build
run: |
BUILD_PARAMS="android bin installer"
if [ "$GITHUB_REF_NAME" == "develop" ] || [ "$GITHUB_REF_NAME" == "main" ]; then
BUILD_PARAMS="$BUILD_PARAMS debug release"
else
BUILD_PARAMS="$BUILD_PARAMS release"
fi
if [ "$GITHUB_REF_NAME" != "main" ]; then
BUILD_PARAMS="$BUILD_PARAMS testing"
fi
bash linux/build-nzbget.sh $BUILD_PARAMS

- name: Rename build artifacts
if: github.ref_name != 'main' && github.ref_name != 'develop'
run: |
cd build
SUFFIX="-${GITHUB_REF_NAME/\//-}-bin-android.run"
for FILE in *.run; do
[ -f $FILE ] || continue
NEW_FILE=${FILE/-bin-android.run/$SUFFIX}
mv $FILE $NEW_FILE
done

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-android-installers
path: build/*.run
retention-days: 5
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:

build-linux:
uses: ./.github/workflows/linux.yml


build-android:
uses: ./.github/workflows/android.yml

build-osx:
uses: ./.github/workflows/osx.yml
permissions:
Expand All @@ -34,12 +37,12 @@ jobs:
needs: [build-linux]
permissions:
actions: write

generate-signatures:
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
runs-on: ubuntu-latest
needs: [build-windows, build-linux, build-osx, repack-qnap, build-linux-pkg]
needs: [build-windows, build-linux, build-osx, build-android, repack-qnap, build-linux-pkg]
permissions:
actions: write
steps:
Expand All @@ -52,6 +55,7 @@ jobs:
mkdir -p builds
mv nzbget-windows-installers/* builds || true
mv nzbget-linux-installers/* builds || true
mv nzbget-android-installers/* builds || true
mv nzbget-osx-installers/* builds || true
mv nzbget-qnap-packages/* builds || true
mv nzbget-deb-packages/* builds || true
Expand Down Expand Up @@ -102,6 +106,7 @@ jobs:
name: |
nzbget-windows-installers
nzbget-linux-installers
nzbget-android-installers
nzbget-osx-installers
nzbget-qnap-packages

Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- name: Build
run: |
BUILD_PARAMS="bin installer"
BUILD_PARAMS="linux bin installer"
if [ "$GITHUB_REF_NAME" == "develop" ] || [ "$GITHUB_REF_NAME" == "main" ]; then
BUILD_PARAMS="$BUILD_PARAMS debug release"
else
Expand All @@ -26,7 +26,7 @@ jobs:
if [ "$GITHUB_REF_NAME" != "main" ]; then
BUILD_PARAMS="$BUILD_PARAMS testing"
fi
bash linux/buildroot/build-nzbget.sh $BUILD_PARAMS
bash linux/build-nzbget.sh $BUILD_PARAMS

- name: Rename build artifacts
if: github.ref_name != 'main' && github.ref_name != 'develop'
Expand All @@ -36,7 +36,7 @@ jobs:
for FILE in *.run; do
[ -f $FILE ] || continue
NEW_FILE=${FILE/-bin-linux.run/$SUFFIX}
mv $FILE $NEW_FILE
mv $FILE $NEW_FILE
done

- name: Upload build artifacts
Expand All @@ -45,4 +45,3 @@ jobs:
name: nzbget-linux-installers
path: build/*.run
retention-days: 5

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Synology package are available as SynoCommunity package. [Synology readme](docs/

QNAP packages are available as buildroot packages or via [sherpa](https://github.com/OneCDOnly/sherpa) package manager. [QNAP readme](qnap/README.md)

Android packages are available for Android 5.0+. [Android readme](docs/ANDROID.md)

## Migration from older NZBGet versions

[Migrating from NZBGet v21 or older](https://github.com/nzbgetcom/nzbget/discussions/100#discussioncomment-8080102)
Expand Down
16 changes: 14 additions & 2 deletions cmake/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ set(CMAKE_SYSTEM_PROCESSOR ${ARCH})

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

if(NOT COMPILER)
set(COMPILER "gcc" CACHE STRING "")
endif()

if("${COMPILER}" STREQUAL "gcc")
set(C_COMPILER "gcc")
set(CXX_COMPILER "g++")
else()
set(C_COMPILER ${COMPILER})
set(CXX_COMPILER ${COMPILER}++)
endif()

set(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar)
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}-as)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-${C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-${CXX_COMPILER})
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-ranlib)
Expand Down
34 changes: 34 additions & 0 deletions docs/ANDROID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Installation on Android

## Installation
All steps to perform on your Android device:
- using web-browser download NZBGet installer app https://github.com/nzbgetcom/android/releases

**NOTE**: this app is only a frontend to NZBGet downloader background process, which
the app installs and launches. The app isn't updated often but it always installs the latest version of nzbget by downloading it from NZBGet download page.

**NOTE**: the installer app requires Android 5 or later.

- install downloaded **apk-file**. You may need to enable a setting allowing installation of apps outside of Play store
- launch NZBGet app
- click **INSTALL DAEMON**
- choose version to install
- the installer app downloads the Android installer package of NZBGet and performs the installation
- the success of installation is confirmed with message "NZBGet daemon has been successfully installed"

## Usage
- to start downloader process launch NZBGet app and choose **START DAEMON**. You get a confirmation about successful start.
- in NZBGet app choose **Show web-interface**; that opens a web-browser. Alternatively open a web-browser manually and navigate to **http://localhost:6789**. Alternatively open a web-browser on your PC or any other device on the same network and navigate to **http://ip-of-android-device:6789**.
- at this point you can close NZBGet app, the daemon process remains running in background;
- use web-interface to control NZBGet daemon.

## Accessing downloaded files

On the external storage, Android apps are only allowed to write into the app specific folder (e. g. '/storage/XXXX-XXXX/Android/data/net.nzbget.nzbget').

To work around this, you may choose any path on the external storage using the **CHOOSE PATHS** button in installer app. Downloads will be moved to these paths after they have finished successfully. All downloads will be moved to the default path unless a path for the category of a specific download is chosen, in which case it will be moved there instead.

**NOTE**: This feature will only move finished downloads from the DestDir you chose in the NZBGet Settings, so don't remove your DestDir in the web interface.

## Post-processing scripts
Most scripts are written in Python. Unfortunately there is no Python for Android. That means most scripts will not work. Bash scripts may work but you may need to install BusyBox from Play store. You also must configure option **ScriptDir** to system partition (scripts cannot be launched from sdcard). Post-processing scripts do not work properly due to OS limitations.
95 changes: 95 additions & 0 deletions linux/android/build-toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash
#
# This file is part of nzbget. See <http://nzbget.net>.
#
# Copyright (C) 2018 Andrey Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2024 phnzb <pavel@nzbget.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script builds cross-compiling toolchain, which can compile NZBGet for Android.
# The toolchain itself runs on Linux.

# Setup strict bash error handling
set -e

# Android API level
APILEVEL=21

# Architecture
ARCH=$1
case "$ARCH" in
i686)
NDK_ARCH="x86"
NDK_TARGET="i686-linux-android"
;;
x86_64)
NDK_ARCH="x86_64"
NDK_TARGET="x86_64-linux-android"
;;
armhf)
NDK_ARCH="arm"
NDK_TARGET="arm-linux-androideabi"
;;
aarch64)
NDK_ARCH="arm64"
NDK_TARGET="aarch64-linux-android"
;;
*)
echo "Usage: $0 (i686|x86_64|armhf|aarch64)"
exit 1
;;
esac

echo "Creating toolchain for $ARCH"

# Android NDK
NDK_VERSION="r19c"
NDK_DIRNAME="android-ndk-$NDK_VERSION"
NDK_ARCHIVE="$NDK_DIRNAME-linux-x86_64.zip"
NDK_URL="https://dl.google.com/android/repository/$NDK_ARCHIVE"

### START OF THE SCRIPT

ROOTDIR="/build/android"
ROOTDIR="$ROOTDIR/$ARCH-ndk"

rm -rf $ROOTDIR
mkdir -p $ROOTDIR

# Download all required tools and libraries
cd ..
SRCDIR=/build/source
mkdir -p $SRCDIR
cd $SRCDIR
if [ ! -d android-ndk -a ! -f $NDK_ARCHIVE ]; then
wget $NDK_URL
fi
cd $ROOTDIR
cd ..

# Unpack NDK
if [ ! -d android-ndk ]; then
echo "Unpacking NDK"
unzip $SRCDIR/$NDK_ARCHIVE
mv $NDK_DIRNAME android-ndk
fi

# Create toolchain for target
echo "Preparing standalone NDK toolchain"
python3 android-ndk/build/tools/make_standalone_toolchain.py --arch $NDK_ARCH --api $APILEVEL --install-dir $ROOTDIR/output/host/usr
cd $ROOTDIR
ln -s host/usr/sysroot output/staging
echo "Toolchain creation completed for $ARCH"
66 changes: 50 additions & 16 deletions linux/buildroot/build-info.md → linux/build-info.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
# About

`build-nzbget.sh` is a bash script which is used to build linux nzbget packages.
`build-nzbget.sh` is a bash script which is used to build linux and android nzbget packages.

Supported architectures: `armel` `armhf` `aarch64` `i686` `x86_64` `riscv64` `mipseb` `mipsel` `ppc500` `ppc6xx`
Supported linux architectures: `armel` `armhf` `aarch64` `i686` `x86_64` `riscv64` `mipseb` `mipsel` `ppc500` `ppc6xx`

Supported android architectures: `i686-ndk` `x86_64-ndk` `armhf-ndk` `aarch64-ndk`

# Prerequisites

1. Linux x86_64 host (Ubuntu 22.04 LTS for example)
2. Installed build dependencies (Ubuntu/Debian example):
```
sudo apt install autoconf automake bc build-essential cmake cpio curl file git libtool pkg-config rsync unzip wget
sudo apt install autoconf automake bc build-essential cmake cpio curl file git libtool pkg-config rsync unzip wget libtinfo5
```
3. Installed buildroot - one per architecture (see [Buildroot setup](#buildroot-setup) below)
4. Installed Android NDK and standalone Android toolkits - one per architecture (see [NDK setup](#ndk-setup) below)

# Building NZBGet

From the cloned repository, run:
```
bash linux/buildroot/build-nzbget.sh [architectures] [output] [configs] [testing] [corex]
bash linux/build-nzbget.sh [platforms] [architectures] [output] [configs] [testing] [corex]
```

Build options:
- platforms: default value `linux android`
- linux: build linux packages
- android: build android packages
- architectures: default value `all`
- armel
- armhf
- aarch64
- i686
- x86_64
- riscv64
- mipsel
- mipseb
- ppc500
- ppc6xx
- linux:
- armel
- armhf
- aarch64
- i686
- x86_64
- riscv64
- mipsel
- mipseb
- ppc500
- ppc6xx
- android:
- i686-ndk
- x86_64-ndk
- armhf-ndk
- aarch64-ndk
- output: default value `bin installer`
- bin: build binary package
- installer: build installer package
Expand All @@ -45,8 +57,8 @@ Build options:

# Output files

- build/*.tar.gz - one file per platform - binary package
- build/*.run - installer package
- build/*.tar.gz - one file per architecture - binary package
- build/*.run - one file per platform - installer package

# Buildroot setup

Expand Down Expand Up @@ -120,3 +132,25 @@ If you want to build all supported toolchains, run
```
for ARCH in aarch64 armel armhf i686 x86_64 riscv64 mipseb mipsel ppc500 ppc6xx; do bash linux/buildroot/build-toolchain.sh $ARCH; done
```

# NDK setup

Script assumes that andriod toolchains is installed in `/build/android/` - one folder per architecture.

To install Android toolchain and NDK:

Make the /build directory and add the necessary permissions.
```
sudo mkdir -p /build
sudo chmod 777 /build
```

From the cloned repository, run:
```
bash linux/android/build-toolchain.sh [architecture]
```

If you want to build all supported toolchains, run
```
for ARCH in i686 x86_64 armhf aarch64; do bash linux/android/build-toolchain.sh $ARCH; done
```
Loading

0 comments on commit 7f8360c

Please sign in to comment.