electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 1253e3db1d9cb5ca9f3eff325f28ffb7035fb497
parent 124d2e23b7f46863cafb47f2b69b6ba4e07d6791
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 29 Nov 2018 16:34:49 +0100

Merge pull request #4873 from SomberNight/android_docker

android docker build
Diffstat:
Mcontrib/make_apk | 2++
Melectrum/gui/kivy/Makefile | 2+-
Melectrum/gui/kivy/Readme.md | 167++++++++++++++++++++-----------------------------------------------------------
Aelectrum/gui/kivy/tools/Dockerfile | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Melectrum/gui/kivy/tools/buildozer.spec | 4++--
5 files changed, 188 insertions(+), 129 deletions(-)

diff --git a/contrib/make_apk b/contrib/make_apk @@ -2,6 +2,8 @@ pushd ./electrum/gui/kivy/ +make theming + if [[ -n "$1" && "$1" == "release" ]] ; then echo -n Keystore Password: read -s password diff --git a/electrum/gui/kivy/Makefile b/electrum/gui/kivy/Makefile @@ -11,7 +11,7 @@ prepare: @cp tools/buildozer.spec ../../../buildozer.spec # copy electrum to main.py @cp ../../../run_electrum ../../../main.py - @-if [ ! -d "../../.buildozer" ];then \ + @-if [ ! -d "../../../.buildozer" ];then \ cd ../../..; buildozer android debug;\ cp -f electrum/gui/kivy/tools/blacklist.txt .buildozer/android/platform/python-for-android/src/blacklist.txt;\ rm -rf ./.buildozer/android/platform/python-for-android/dist;\ diff --git a/electrum/gui/kivy/Readme.md b/electrum/gui/kivy/Readme.md @@ -3,147 +3,62 @@ The Kivy GUI is used with Electrum on Android devices. To generate an APK file, follow these instructions. -Recommended env: Ubuntu 18.04 +## Android binary with Docker -## 1. Preliminaries +This assumes an Ubuntu host, but it should not be too hard to adapt to another +similar system. The docker commands should be executed in the project's root +folder. -Make sure the current user can write `/opt` (e.g. `sudo chown username: /opt`). +1. Install Docker -We assume that you already got Electrum to run from source on this machine, -hence have e.g. `git`, `python3-pip` and `python3-setuptools`. + ``` + $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + $ sudo apt-get update + $ sudo apt-get install -y docker-ce + ``` -## 2. Install kivy +2. Build image -Install kivy for python3 as described [here](https://kivy.org/docs/installation/installation-linux.html). -So for example: -```sh -sudo add-apt-repository ppa:kivy-team/kivy -sudo apt-get install python3-kivy -``` - - -## 3. Install python-for-android (p4a) -p4a is used to package Electrum, Python, SDL and a bootstrap Java app into an APK file. -We need some functionality not in p4a master, so for the time being we have our own fork. - -Something like this should work: - -```sh -cd /opt -git clone https://github.com/kivy/python-for-android -cd python-for-android -git remote add sombernight https://github.com/SomberNight/python-for-android -git fetch --all -git checkout f74226666af69f9915afaee9ef9292db85a6c617 -``` + ``` + $ sudo docker build -t electrum-android-builder-img electrum/gui/kivy/tools + ``` -## 4. Install buildozer -4.1 Buildozer is a frontend to p4a. Luckily we don't need to patch it: +3. Prepare pure python dependencies -```sh -cd /opt -git clone https://github.com/kivy/buildozer -cd buildozer -sudo python3 setup.py install -``` + ``` + $ sudo ./contrib/make_packages + ``` -4.2 Install additional dependencies: +4. Build binaries -```sh -sudo apt-get install python-pip -``` - -(from [buildozer docs](https://buildozer.readthedocs.io/en/latest/installation.html#targeting-android)) -```sh -sudo pip install --upgrade cython==0.21 -sudo dpkg --add-architecture i386 -sudo apt-get update -sudo apt-get install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386 -``` - -4.3 Download Android NDK -```sh -cd /opt -wget https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip -unzip android-ndk-r14b-linux-x86_64.zip -``` - -## 5. Some more dependencies - -```sh -python3 -m pip install colorama appdirs sh jinja2 cython==0.29 -sudo apt-get install autotools-dev autoconf libtool pkg-config python3.7 -``` - - -## 6. Create the UI Atlas -In the `electrum/gui/kivy` directory of Electrum, run `make theming`. - -## 7. Download Electrum dependencies -```sh -sudo contrib/make_packages -``` + ``` + $ sudo docker run -it --rm \ + --name electrum-android-builder-cont \ + -v $PWD:/home/user/wspace/electrum \ + -v ~/.keystore:/home/user/.keystore \ + --workdir /home/user/wspace/electrum \ + electrum-android-builder-img \ + ./contrib/make_apk + ``` + This mounts the project dir inside the container, + and so the modifications will affect it, e.g. `.buildozer` folder + will be created. -## 8. Try building the APK and fail +5. The generated binary is in `./bin`. -### 1. Try and fail: -```sh -contrib/make_apk -``` -Symlink android tools: +## FAQ -```sh -ln -sf ~/.buildozer/android/platform/android-sdk-24/tools ~/.buildozer/android/platform/android-sdk-24/tools.save -``` +### I changed something but I don't see any differences on the phone. What did I do wrong? +You probably need to clear the cache: `rm -rf .buildozer/android/platform/build/{build,dists}` -### 2. Try and fail: -```sh -contrib/make_apk +### How do I get an interactive shell inside docker? ``` - -During this build attempt, buildozer downloaded some tools, -e.g. those needed in the next step. - -## 9. Update the Android SDK build tools - -### Method 1: Using the GUI - - Start the Android SDK manager in GUI mode: - - ~/.buildozer/android/platform/android-sdk-24/tools/android - - Check the latest SDK available and install it - ("Android SDK Tools" and "Android SDK Platform-tools"). - Close the SDK manager. Repeat until there is no newer version. - - Reopen the SDK manager, and install the latest build tools - ("Android SDK Build-tools"), 28.0.3 at the time of writing. - - Install "Android 9">"SDK Platform". - Install "Android Support Repository" from the SDK manager (under "Extras"). - -### Method 2: Using the command line: - - Repeat the following command until there is nothing to install: - - ~/.buildozer/android/platform/android-sdk-24/tools/android update sdk -u -t tools,platform-tools - - Install Build Tools, android API 19 and Android Support Library: - - ~/.buildozer/android/platform/android-sdk-24/tools/android update sdk -u -t build-tools-28.0.3,android-28,extra-android-m2repository - - (FIXME: build-tools is not getting installed?! use GUI for now.) - -## 10. Build the APK - -```sh -contrib/make_apk +$ sudo docker run -it --rm \ + -v $PWD:/home/user/wspace/electrum \ + --workdir /home/user/wspace/electrum \ + electrum-android-builder-img ``` - -# FAQ - -## I changed something but I don't see any differences on the phone. What did I do wrong? -You probably need to clear the cache: `rm -rf .buildozer/android/platform/build/{build,dists}` diff --git a/electrum/gui/kivy/tools/Dockerfile b/electrum/gui/kivy/tools/Dockerfile @@ -0,0 +1,142 @@ +# based on https://github.com/kivy/python-for-android/blob/master/Dockerfile + +FROM ubuntu:18.04 + +ENV ANDROID_HOME="/opt/android" + +RUN apt -y update -qq \ + && apt -y install -qq --no-install-recommends curl unzip git python3-pip python3-setuptools \ + && apt -y autoremove \ + && apt -y clean + + +ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk" +ENV ANDROID_NDK_VERSION="14b" +ENV ANDROID_NDK_HOME_V="${ANDROID_NDK_HOME}-r${ANDROID_NDK_VERSION}" + +# get the latest version from https://developer.android.com/ndk/downloads/index.html +ENV ANDROID_NDK_ARCHIVE="android-ndk-r${ANDROID_NDK_VERSION}-linux-x86_64.zip" +ENV ANDROID_NDK_DL_URL="https://dl.google.com/android/repository/${ANDROID_NDK_ARCHIVE}" + +# download and install Android NDK +RUN curl --location --progress-bar \ + "${ANDROID_NDK_DL_URL}" \ + --output "${ANDROID_NDK_ARCHIVE}" \ + && mkdir --parents "${ANDROID_NDK_HOME_V}" \ + && unzip -q "${ANDROID_NDK_ARCHIVE}" -d "${ANDROID_HOME}" \ + && ln -sfn "${ANDROID_NDK_HOME_V}" "${ANDROID_NDK_HOME}" \ + && rm -rf "${ANDROID_NDK_ARCHIVE}" + + +ENV ANDROID_SDK_HOME="${ANDROID_HOME}/android-sdk" + +# get the latest version from https://developer.android.com/studio/index.html +ENV ANDROID_SDK_TOOLS_VERSION="4333796" +ENV ANDROID_SDK_TOOLS_ARCHIVE="sdk-tools-linux-${ANDROID_SDK_TOOLS_VERSION}.zip" +ENV ANDROID_SDK_TOOLS_DL_URL="https://dl.google.com/android/repository/${ANDROID_SDK_TOOLS_ARCHIVE}" + +# download and install Android SDK +RUN curl --location --progress-bar \ + "${ANDROID_SDK_TOOLS_DL_URL}" \ + --output "${ANDROID_SDK_TOOLS_ARCHIVE}" \ + && mkdir --parents "${ANDROID_SDK_HOME}" \ + && unzip -q "${ANDROID_SDK_TOOLS_ARCHIVE}" -d "${ANDROID_SDK_HOME}" \ + && rm -rf "${ANDROID_SDK_TOOLS_ARCHIVE}" + +# update Android SDK, install Android API, Build Tools... +RUN mkdir --parents "${ANDROID_SDK_HOME}/.android/" \ + && echo '### User Sources for Android SDK Manager' \ + > "${ANDROID_SDK_HOME}/.android/repositories.cfg" + +# accept Android licenses (JDK necessary!) +RUN apt -y update -qq \ + && apt -y install -qq --no-install-recommends openjdk-8-jdk \ + && apt -y autoremove \ + && apt -y clean +RUN yes | "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" --licenses > /dev/null + +# download platforms, API, build tools +RUN "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "platforms;android-24" && \ + "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "platforms;android-28" && \ + "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "build-tools;28.0.3" && \ + "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "extras;android;m2repository" && \ + chmod +x "${ANDROID_SDK_HOME}/tools/bin/avdmanager" + + +ENV USER="user" +ENV HOME_DIR="/home/${USER}" +ENV WORK_DIR="${HOME_DIR}/wspace" \ + PATH="${HOME_DIR}/.local/bin:${PATH}" + +# install system dependencies +RUN apt -y update -qq \ + && apt -y install -qq --no-install-recommends \ + python virtualenv python-pip wget lbzip2 patch sudo \ + software-properties-common + +# install kivy +RUN add-apt-repository ppa:kivy-team/kivy \ + && apt -y update -qq \ + && apt -y install -qq --no-install-recommends python3-kivy \ + && apt -y autoremove \ + && apt -y clean +RUN python3 -m pip install image + +# build dependencies +# https://buildozer.readthedocs.io/en/latest/installation.html#android-on-ubuntu-16-04-64bit +RUN dpkg --add-architecture i386 \ + && apt -y update -qq \ + && apt -y install -qq --no-install-recommends \ + build-essential ccache git python2.7 python2.7-dev \ + libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 \ + libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 \ + zip zlib1g-dev zlib1g:i386 \ + && apt -y autoremove \ + && apt -y clean + +# specific recipes dependencies (e.g. libffi requires autoreconf binary) +RUN apt -y update -qq \ + && apt -y install -qq --no-install-recommends \ + autoconf automake cmake gettext libltdl-dev libtool pkg-config \ + python3.7 \ + && apt -y autoremove \ + && apt -y clean + + +# prepare non root env +RUN useradd --create-home --shell /bin/bash ${USER} + +# with sudo access and no password +RUN usermod -append --groups sudo ${USER} +RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + + +WORKDIR ${WORK_DIR} + +# user needs ownership/write access to these directories +RUN chown --recursive ${USER} ${WORK_DIR} ${ANDROID_SDK_HOME} +RUN chown ${USER} /opt +USER ${USER} + + +RUN pip install --upgrade cython==0.29 +RUN python3 -m pip install --upgrade cython==0.29 + +# install buildozer +RUN cd /opt \ + && git clone https://github.com/kivy/buildozer \ + && cd buildozer \ + && python3 -m pip install -e . + +# install python-for-android +RUN cd /opt \ + && git clone https://github.com/kivy/python-for-android \ + && cd python-for-android \ + && git remote add sombernight https://github.com/SomberNight/python-for-android \ + && git fetch --all \ + && git checkout f74226666af69f9915afaee9ef9292db85a6c617 \ + && python3 -m pip install -e . + +# build env vars +ENV USE_SDK_WRAPPER=1 +ENV GRADLE_OPTS="-Xmx1536M -Dorg.gradle.jvmargs='-Xmx1536M'" diff --git a/electrum/gui/kivy/tools/buildozer.spec b/electrum/gui/kivy/tools/buildozer.spec @@ -70,10 +70,10 @@ android.ndk = 14b android.private_storage = True # (str) Android NDK directory (if empty, it will be automatically downloaded.) -android.ndk_path = /opt/android-ndk-r14b +android.ndk_path = /opt/android/android-ndk # (str) Android SDK directory (if empty, it will be automatically downloaded.) -#android.sdk_path = +android.sdk_path = /opt/android/android-sdk # (str) Android entry point, default is ok for Kivy-based app #android.entrypoint = org.renpy.android.PythonActivity