├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── README.md ├── androidbuildlib ├── build_all.sh ├── build_aria2.sh ├── build_libssh2.sh └── build_openssl.sh /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build aria2 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | with: 14 | submodules: true 15 | - name: Setup NDK 16 | run: | 17 | sudo apt-get update 18 | sudo apt-get install -y autoconf automake autopoint autotools-dev libtool libxml2-dev libcppunit-dev 19 | wget https://dl.google.com/android/repository/android-ndk-r23b-linux.zip 20 | unzip -q android-ndk-r23b-linux.zip 21 | export ANDROID_NDK_HOME=`pwd`/android-ndk-r23b 22 | export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH 23 | export SILENT=true 24 | - name: Build 25 | run: | 26 | ./build_all.sh 27 | file ./bin/armeabi-v7a/bin/aria2c 28 | file ./bin/arm64-v8a/bin/aria2c 29 | file ./bin/x86/bin/aria2c 30 | file ./bin/x86_64/bin/aria2c 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /libs 2 | /bin -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "aria2"] 2 | path = aria2 3 | url = https://github.com/aria2/aria2 4 | [submodule "c-ares"] 5 | path = c-ares 6 | url = https://github.com/c-ares/c-ares 7 | [submodule "libexpat"] 8 | path = libexpat 9 | url = https://github.com/libexpat/libexpat 10 | [submodule "zlib"] 11 | path = zlib 12 | url = https://github.com/madler/zlib 13 | [submodule "openssl"] 14 | path = openssl 15 | url = https://github.com/openssl/openssl 16 | [submodule "libssh2"] 17 | path = libssh2 18 | url = https://github.com/libssh2/libssh2 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aria2-android 2 | [![Build Status](https://travis-ci.com/devgianlu/aria2-android.svg?branch=master)](https://travis-ci.com/devgianlu/aria2-android) 3 | 4 | All you need to cross-compile [aria2](https://github.com/aria2/aria2) for Android. 5 | 6 | ## Build 7 | 8 | Clone the repository with submodules (`--recurse-submodules`), install the Android NDK r20, set the `ANDROID_NDK_HOME` env variable and run `./build_all.sh`. 9 | 10 | This will compile aria2 for `armeavi-v7a`, `arm64-v8a`, `x86` and `x86_64`. The binaries can be found inside the `bin` folder. 11 | -------------------------------------------------------------------------------- /androidbuildlib: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | print_help() 4 | { 5 | __text=" 6 | Configurable parameters 7 | out_path - target installation path to install generated library files for all archs, 8 | it need to be in relative path from the directory executing this script [default is libs] 9 | host_tag - host value that will build the library (hint: you can take a look for this value 10 | at your \$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/ [default is linux-x86_64] 11 | minsdkversion - minimum sdk version to support, this is value of api level [default is 18] 12 | target_abis - target abis to build for, separated by space [default is \"armeabi-v7a x86 arm64-v8a x86_64\"] 13 | configure_params - additional params to pass to ./configure 14 | fresh_build - whether or not this is a fresh build, user might be using this when repeatitively build the same project over and over i.e. while debugging, so there's no need to keep re-execute './configure' and 'make clean' again. [default is true] 15 | no_host - whether ./configure should be called with the --host option [default is false] 16 | silent - whether the compilation should be less verbose [default is false] 17 | custom_silent - custom silent flag/option [default is \"--enable-silent-rules\"] 18 | " 19 | echo "$__text" 20 | } 21 | 22 | # print help 23 | if [ "$1" == "--help" ] 24 | then 25 | print_help 26 | exit 27 | fi 28 | 29 | # check for existence of configure, and Makefile 30 | if [ ! -e configure ] && { [ ! -e Makefile ] || [ ! -e makefile ]; } 31 | then 32 | echo "Cannot find either configure or Makefile file" 33 | exit 1 34 | fi 35 | 36 | out_path=libs 37 | # check system is linux or darwin 38 | if [ "$(uname)" == "Darwin" ]; then 39 | host_tag=darwin-x86_64 40 | else 41 | host_tag=linux-x86_64 42 | fi 43 | minsdkversion=18 44 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" 45 | configure_params="" 46 | fresh_build=true 47 | no_host=false 48 | silent=false 49 | custom_silent="--enable-silent-rules" 50 | # support build zlib use the default value linux when build on macOS. 51 | chost="linux" 52 | 53 | for ARGUMENT in "$@" 54 | do 55 | KEY=$(echo $ARGUMENT | cut -f1 -d=) 56 | VALUE=$(echo $ARGUMENT | cut -f2- -d=) 57 | 58 | case "$KEY" in 59 | "no_host" ) no_host="${VALUE}" ;; 60 | "out_path" ) out_path="${VALUE}" ;; 61 | "host_tag" ) host_tag="${VALUE}" ;; 62 | "minsdkversion" ) minsdkversion="${VALUE}" ;; 63 | "target_abis" ) target_abis="${VALUE}" ;; 64 | "configure_params" ) configure_params="${VALUE}" ;; 65 | "fresh_build" ) fresh_build="${VALUE}" ;; 66 | "silent" ) silent="${VALUE}" ;; 67 | "custom_silent" ) custom_silent="${VALUE}" ;; 68 | *) 69 | echo "" 70 | echo "Unknown '$KEY' parameter" 71 | print_help 72 | exit 1 73 | ;; 74 | esac 75 | done 76 | 77 | echo "" 78 | echo "-Will use following setting-" 79 | echo "output = $out_path" 80 | echo "host_tag = $host_tag" 81 | echo "minsdkversion = $minsdkversion" 82 | echo "target_abis = $target_abis" 83 | echo "configure_params = $configure_params" 84 | echo "fresh_build = $fresh_build" 85 | echo "no_host = $no_host" 86 | echo "silent = $silent" 87 | echo "custom_silent = $custom_silent" 88 | echo "chost = $chost" 89 | echo "" 90 | 91 | # check to create installation dir of built library files 92 | if [ ! -d "$out_path" ] 93 | then 94 | mkdir "$out_path" 95 | 96 | for dir in $target_abis 97 | do 98 | if [ ! -d "$out_path"/"$dir" ] 99 | then 100 | mkdir "$out_path"/"$dir" 101 | fi 102 | done 103 | fi 104 | 105 | export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$host_tag 106 | 107 | for target in $target_abis 108 | do 109 | if [ $target == "armeabi-v7a" ] 110 | then 111 | echo "prepare for armeabi-v7a" 112 | cc_prefix=armv7a-linux-androideabi$minsdkversion- 113 | support_prefix=arm-linux-androideabi- 114 | host=armv7a-linux-androideabi 115 | install_dir=`pwd`/"$out_path"/armeabi-v7a 116 | CFLAGS="${CFLAGS} -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" 117 | elif [ $target == "x86" ] 118 | then 119 | echo "prepare for x86" 120 | cc_prefix=i686-linux-android$minsdkversion- 121 | support_prefix=i686-linux-android- 122 | host=i686-linux-android 123 | install_dir=`pwd`/"$out_path"/x86 124 | CFLAGS="${CFLAGS} -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32" 125 | elif [ $target == "arm64-v8a" ] 126 | then 127 | echo "prepare for arm64-v8a" 128 | cc_prefix=aarch64-linux-android$minsdkversion- 129 | support_prefix=aarch64-linux-android- 130 | host=aarch64-linux-android 131 | install_dir=`pwd`/"$out_path"/arm64-v8a 132 | else 133 | echo "prepare for x86_64" 134 | cc_prefix=x86_64-linux-android$minsdkversion- 135 | support_prefix=x86_64-linux-android- 136 | host=x86_64-linux-android 137 | install_dir=`pwd`/"$out_path"/x86_64 138 | CFLAGS="${CFLAGS} -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel" 139 | fi 140 | 141 | echo "" 142 | echo "cc_prefix = $cc_prefix" 143 | echo "support_prefix = $support_prefix" 144 | echo "host = $host" 145 | echo "install_dir = $install_dir" 146 | echo "CFLAGS = $CFLAGS" 147 | echo "" 148 | 149 | export AR=$TOOLCHAIN/bin/llvm-ar 150 | export CC=$TOOLCHAIN/bin/${cc_prefix}clang 151 | export AS=$CC 152 | export CXX=$TOOLCHAIN/bin/${cc_prefix}clang++ 153 | export LD=$TOOLCHAIN/bin/ld 154 | export RANLIB=$TOOLCHAIN/bin/llvm-ranlib 155 | export STRIP=$TOOLCHAIN/bin/llvm-strip 156 | export CHOST=$chost 157 | 158 | # only confiture and make clean when there's no flag telling to ignore 159 | if [ "$fresh_build" == "true" ] 160 | then 161 | VERBOSE_FLAGS="" 162 | if [ "$silent" == "true" ] 163 | then 164 | VERBOSE_FLAGS="-s V=0" 165 | configure_params="$custom_silent $configure_params" 166 | fi 167 | 168 | if [ "$no_host" == "true" ] 169 | then 170 | ./configure --prefix="$install_dir" $configure_params || exit 171 | else 172 | ./configure --host="$host" --prefix="$install_dir" $configure_params || exit 173 | fi 174 | 175 | make $VERBOSE_FLAGS clean || exit 176 | fi 177 | 178 | make -j4 $VERBOSE_FLAGS || exit 179 | make install || exit 180 | echo "Done building $target" 181 | done 182 | 183 | echo "All done" 184 | -------------------------------------------------------------------------------- /build_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Check NDK and ANDROID_NDK_HOME env 4 | if [ -z "$NDK" ]; then 5 | if [ -z "$ANDROID_NDK_HOME" ]; then 6 | echo 'No $NDK or $ANDROID_NDK_HOME specified.' 7 | exit 1 8 | else 9 | export NDK="$ANDROID_NDK_HOME" 10 | fi 11 | else 12 | export ANDROID_NDK_HOME="$NDK" 13 | fi 14 | 15 | 16 | # Clean 17 | rm -rf libs 18 | rm -rf bin 19 | 20 | 21 | # Build c-ares 22 | cd c-ares 23 | echo "----- Build c-ares (`git describe --tags`) -----" 24 | autoreconf -i 25 | ../androidbuildlib out_path=../libs minsdkversion=24 \ 26 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" \ 27 | silent="$SILENT" custom_silent="--silent" \ 28 | configure_params="--disable-shared --enable-static" 29 | cd .. 30 | 31 | 32 | # Build expat 33 | cd libexpat/expat 34 | echo -e "\n\n----- Build expat (`git describe --tags`) -----" 35 | ./buildconf.sh 36 | ../../androidbuildlib out_path=../../libs minsdkversion=24 \ 37 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" \ 38 | silent="$SILENT" \ 39 | configure_params="--disable-shared --enable-static" 40 | cd ../.. 41 | 42 | 43 | # Build zlib 44 | cd zlib 45 | echo -e "\n\n----- Build zlib (`git describe --tags`) -----" 46 | ../androidbuildlib out_path=../libs minsdkversion=24 \ 47 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" \ 48 | no_host="true" \ 49 | silent="$SILENT" custom_silent="" \ 50 | configure_params="--static" 51 | cd .. 52 | 53 | 54 | # Build openssl 55 | ./build_openssl.sh "$(pwd)/libs" 56 | 57 | 58 | # Build libssh2 59 | ./build_libssh2.sh "$(pwd)/libs" 60 | 61 | 62 | # Build aria2 63 | ./build_aria2.sh minsdkversion=24 \ 64 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" \ 65 | silent="$SILENT" 66 | -------------------------------------------------------------------------------- /build_aria2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | 4 | LIBS_DIR=$(pwd)/libs 5 | INSTALL_DIR=$(pwd)/bin 6 | mkdir -p $INSTALL_DIR 7 | 8 | cd aria2 9 | autoreconf -i 10 | 11 | 12 | print_help() 13 | { 14 | __text=" 15 | Configurable parameters 16 | host_tag - host value that will build the library (hint: you can take a look for this value 17 | at your \$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/ [default is linux-x86_64] 18 | minsdkversion - minimum sdk version to support, this is value of api level [default is 18] 19 | target_abis - target abis to build for, separated by space [default is \"armeabi-v7a x86 arm64-v8a x86_64\"] 20 | silent - whether the compilation should be less verbose 21 | " 22 | echo "$__text" 23 | } 24 | 25 | # print help 26 | if [ "$1" == "--help" ] 27 | then 28 | print_help 29 | exit 30 | fi 31 | 32 | # check for existence of configure, and Makefile 33 | if [ ! -e configure ] && { [ ! -e Makefile ] || [ ! -e makefile ]; } 34 | then 35 | echo "Cannot find either configure or Makefile file" 36 | exit 1 37 | fi 38 | 39 | # check system is linux or darwin 40 | if [ "$(uname)" == "Darwin" ]; then 41 | host_tag=darwin-x86_64 42 | else 43 | host_tag=linux-x86_64 44 | fi 45 | minsdkversion=18 46 | target_abis="armeabi-v7a x86 arm64-v8a x86_64" 47 | silent=false 48 | 49 | for ARGUMENT in "$@" 50 | do 51 | KEY=$(echo $ARGUMENT | cut -f1 -d=) 52 | VALUE=$(echo $ARGUMENT | cut -f2- -d=) 53 | 54 | case "$KEY" in 55 | "host_tag" ) host_tag="${VALUE}" ;; 56 | "minsdkversion" ) minsdkversion="${VALUE}" ;; 57 | "target_abis" ) target_abis="${VALUE}" ;; 58 | "silent" ) silent="${VALUE}" ;; 59 | *) 60 | echo "" 61 | echo "Unknown '$KEY' parameter" 62 | print_help 63 | exit 1 64 | ;; 65 | esac 66 | done 67 | 68 | echo "" 69 | echo "-Will use following setting-" 70 | echo "host_tag = $host_tag" 71 | echo "minsdkversion = $minsdkversion" 72 | echo "target_abis = $target_abis" 73 | echo "silent = $silent" 74 | echo "" 75 | 76 | export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$host_tag 77 | 78 | 79 | for target in $target_abis 80 | do 81 | if [ $target == "armeabi-v7a" ] 82 | then 83 | echo "prepare for armeabi-v7a" 84 | cc_prefix=armv7a-linux-androideabi$minsdkversion- 85 | support_prefix=arm-linux-androideabi- 86 | host=armv7a-linux-androideabi 87 | install_dir=$INSTALL_DIR/armeabi-v7a 88 | CFLAGS="${CFLAGS} -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" 89 | elif [ $target == "x86" ] 90 | then 91 | echo "prepare for x86" 92 | cc_prefix=i686-linux-android$minsdkversion- 93 | support_prefix=i686-linux-android- 94 | host=i686-linux-android 95 | install_dir=$INSTALL_DIR/x86 96 | CFLAGS="${CFLAGS} -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32" 97 | elif [ $target == "arm64-v8a" ] 98 | then 99 | echo "prepare for arm64-v8a" 100 | cc_prefix=aarch64-linux-android$minsdkversion- 101 | support_prefix=aarch64-linux-android- 102 | host=aarch64-linux-android 103 | install_dir=$INSTALL_DIR/arm64-v8a 104 | else 105 | echo "prepare for x86_64" 106 | cc_prefix=x86_64-linux-android$minsdkversion- 107 | support_prefix=x86_64-linux-android- 108 | host=x86_64-linux-android 109 | install_dir=$INSTALL_DIR/x86_64 110 | CFLAGS="${CFLAGS} -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel" 111 | fi 112 | 113 | echo "" 114 | echo "cc_prefix = $cc_prefix" 115 | echo "support_prefix = $support_prefix" 116 | echo "host = $host" 117 | echo "install_dir = $install_dir" 118 | echo "CFLAGS = $CFLAGS" 119 | echo "" 120 | 121 | export AR=$TOOLCHAIN/bin/llvm-ar 122 | export CC=$TOOLCHAIN/bin/${cc_prefix}clang 123 | export AS=$CC 124 | export CXX=$TOOLCHAIN/bin/${cc_prefix}clang++ 125 | export LD=$TOOLCHAIN/bin/ld 126 | export RANLIB=$TOOLCHAIN/bin/llvm-ranlib 127 | export STRIP=$TOOLCHAIN/bin/llvm-strip 128 | 129 | configure_params="" 130 | make_params="" 131 | if [ "$silent" == "true" ] 132 | then 133 | make_params="-s V=0" 134 | configure_params="--silent" 135 | fi 136 | 137 | LIBS_TARGET_DIR=$LIBS_DIR/$target 138 | 139 | ./configure \ 140 | --host="$host" \ 141 | --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 142 | --prefix="$install_dir" \ 143 | --disable-nls \ 144 | --without-gnutls \ 145 | --with-openssl \ 146 | --without-sqlite3 \ 147 | --without-libxml2 \ 148 | --with-libexpat \ 149 | --with-libcares \ 150 | --with-libz \ 151 | --with-libssh2 \ 152 | $configure_params \ 153 | CXXFLAGS="-Os -g" \ 154 | CFLAGS="-Os -g" \ 155 | CPPFLAGS="-fPIE" \ 156 | LDFLAGS="-fPIE -pie -L$LIBS_TARGET_DIR/lib -static-libstdc++" \ 157 | PKG_CONFIG_LIBDIR="$LIBS_TARGET_DIR/lib/pkgconfig" || exit 158 | 159 | 160 | make $make_params clean || exit 161 | make -j `nproc` $make_params || exit 162 | make install || exit 163 | echo "Done building $target" 164 | done 165 | 166 | echo "All done" 167 | -------------------------------------------------------------------------------- /build_libssh2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | cd libssh2 4 | echo -e "\n\n----- Build libssh2 (`git describe --tags`) -----" 5 | ./buildconf 6 | 7 | INSTALL_DIR="$1" 8 | export LDFLAGS="$LDFLAGS -latomic" 9 | 10 | echo -e "\n++ Build libssh2 armeabi-v7a ++" 11 | ../androidbuildlib out_path=../libs \ 12 | minsdkversion=21 \ 13 | target_abis="armeabi-v7a" \ 14 | configure_params="--disable-shared --enable-static --with-libssl-prefix=$INSTALL_DIR/armeabi-v7a" \ 15 | silent="$SILENT" custom_silent="--silent" 16 | 17 | echo -e "\n++ Build libssh2 x86 ++" 18 | ../androidbuildlib out_path=../libs \ 19 | minsdkversion=21 \ 20 | target_abis="x86" \ 21 | configure_params="--disable-shared --enable-static --with-libssl-prefix=$INSTALL_DIR/x86" \ 22 | silent="$SILENT" custom_silent="--silent" 23 | 24 | echo -e "\n++ Build libssh2 arm64-v8a ++" 25 | ../androidbuildlib out_path=../libs \ 26 | minsdkversion=21 \ 27 | target_abis="arm64-v8a" \ 28 | configure_params="--disable-shared --enable-static --with-libssl-prefix=$INSTALL_DIR/arm64-v8a" \ 29 | silent="$SILENT" custom_silent="--silent" 30 | 31 | echo -e "\n++ Build libssh2 x86_64 ++" 32 | ../androidbuildlib out_path=../libs \ 33 | minsdkversion=21 \ 34 | target_abis="x86_64" \ 35 | configure_params="--disable-shared --enable-static --with-libssl-prefix=$INSTALL_DIR/x86_64" \ 36 | silent="$SILENT" custom_silent="--silent" 37 | 38 | cd .. -------------------------------------------------------------------------------- /build_openssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | cd openssl 4 | INSTALL_DIR="$1" 5 | # openssl configure script will check ANDROID_NDK_ROOT 6 | export ANDROID_NDK_ROOT="$NDK" 7 | # check system is linux or darwin 8 | if [ "$(uname)" == "Darwin" ]; then 9 | host_tag=darwin-x86_64 10 | else 11 | host_tag=linux-x86_64 12 | fi 13 | export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$host_tag/bin:$PATH 14 | echo -e "\n\n----- Build openssl (`git describe --tags`) -----" 15 | 16 | VERBOSE_FLAGS="" 17 | if [ "$SILENT" == "true" ]; then 18 | VERBOSE_FLAGS="-s V=0" 19 | echo "Using non-verbose mode" 20 | fi 21 | 22 | # Nov 10, 2021, openssl fix it. https://github.com/openssl/openssl/pull/15086 23 | # now we can use -latomic to fix the build error. 24 | LDFLAGS="-latomic" 25 | 26 | echo -e "\n++ Build openssl armeabi-v7a ++" 27 | ./Configure no-shared android-arm -D__ANDROID_API__=21 --prefix="$INSTALL_DIR/armeabi-v7a" $LDFLAGS 28 | make $VERBOSE_FLAGS clean 29 | make -j4 $VERBOSE_FLAGS 30 | make install_sw 31 | 32 | echo -e "\n++ Build openssl arm64-v8a ++" 33 | ./Configure no-shared android-arm64 -D__ANDROID_API__=21 --prefix="$INSTALL_DIR/arm64-v8a" $LDFLAGS 34 | make $VERBOSE_FLAGS clean 35 | make -j4 $VERBOSE_FLAGS 36 | make install_sw 37 | 38 | echo -e "\n++ Build openssl x86 ++" 39 | ./Configure no-shared android-x86 -D__ANDROID_API__=21 --prefix="$INSTALL_DIR/x86" $LDFLAGS 40 | make $VERBOSE_FLAGS clean 41 | make -j4 $VERBOSE_FLAGS 42 | make install_sw 43 | 44 | echo -e "\n++ Build openssl x86_64 ++" 45 | ./Configure no-shared android-x86_64 -D__ANDROID_API__=21 --prefix="$INSTALL_DIR/x86_64" $LDFLAGS 46 | make $VERBOSE_FLAGS clean 47 | make -j4 $VERBOSE_FLAGS 48 | make install_sw 49 | 50 | cd .. 51 | --------------------------------------------------------------------------------