Skip to content

Commit

Permalink
Qt: add Android packaging support
Browse files Browse the repository at this point in the history
Introduce an android directory under qt and allow one to package bitcoin-qt for Android by running make apk.
Add bitcoin-qt Android build instructions.
  • Loading branch information
icota committed May 3, 2020
1 parent 844d207 commit a818b2c
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 0 deletions.
16 changes: 16 additions & 0 deletions configure.ac
Expand Up @@ -617,6 +617,21 @@ case $host in
*android*)
dnl make sure android stays above linux for hosts like *linux-android*
TARGET_OS=android
case $host in
*x86_64*)
ANDROID_ARCH=x86_64
;;
*aarch64*)
ANDROID_ARCH=arm64-v8a
;;
*armv7a*)
ANDROID_ARCH=armeabi-v7a
;;
*i686*)
ANDROID_ARCH=i686
;;
*) AC_MSG_ERROR("Could not determine Android arch") ;;
esac
;;
*linux*)
TARGET_OS=linux
Expand Down Expand Up @@ -1632,6 +1647,7 @@ AC_SUBST(HAVE_BUILTIN_PREFETCH)
AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL)
AC_SUBST(HAVE_WEAK_GETAUXVAL)
AC_SUBST(ANDROID_ARCH)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
Expand Down
1 change: 1 addition & 0 deletions doc/README.md
Expand Up @@ -44,6 +44,7 @@ The following are developer notes on how to build Bitcoin Core on your native pl
- [FreeBSD Build Notes](build-freebsd.md)
- [OpenBSD Build Notes](build-openbsd.md)
- [NetBSD Build Notes](build-netbsd.md)
- [Android Build Notes](build-android.md)
- [Gitian Building Guide (External Link)](https://github.com/bitcoin-core/docs/blob/master/gitian-building.md)

Development
Expand Down
12 changes: 12 additions & 0 deletions doc/build-android.md
@@ -0,0 +1,12 @@
ANDROID BUILD NOTES
======================

This guide describes how to build and package the `bitcoin-qt` GUI for Android on Linux and macOS.

## Preparation

You will need to get the Android NDK and build dependencies for Android as described in [depends/README.md](../depends/README.md).

## Building and packaging

After the depends are built configure with one of the resulting prefixes and run `make && make apk` in `src/qt`.
14 changes: 14 additions & 0 deletions src/Makefile.qt.include
Expand Up @@ -352,6 +352,20 @@ bitcoin_qt_clean: FORCE

bitcoin_qt : qt/bitcoin-qt$(EXEEXT)

APK_LIB_DIR = qt/android/libs/$(ANDROID_ARCH)
QT_BASE_PATH = $(shell find ../depends/sources/ -maxdepth 1 -type f -regex ".*qtbase.*\.tar.xz")
QT_BASE_TLD = $(shell tar tf $(QT_BASE_PATH) --exclude='*/*')

bitcoin_qt_apk: FORCE
mkdir -p $(APK_LIB_DIR)
cp $(dir $(CC))../sysroot/usr/lib/$(host_alias)/libc++_shared.so $(APK_LIB_DIR)
tar xf $(QT_BASE_PATH) -C qt/android/src/ $(QT_BASE_TLD)src/android/jar/src --strip-components=5
tar xf $(QT_BASE_PATH) -C qt/android/src/ $(QT_BASE_TLD)src/android/java/src --strip-components=5
tar xf $(QT_BASE_PATH) -C qt/android/res/ $(QT_BASE_TLD)src/android/java/res --strip-components=5
cp qt/bitcoin-qt $(APK_LIB_DIR)/libbitcoin-qt.so
cd qt/android && gradle wrapper
cd qt/android && ./gradlew build

ui_%.h: %.ui
@test -f $(UIC)
@$(MKDIR_P) $(@D)
Expand Down
2 changes: 2 additions & 0 deletions src/qt/Makefile
Expand Up @@ -7,3 +7,5 @@ check: FORCE
$(MAKE) -C .. test_bitcoin_qt_check
bitcoin-qt bitcoin-qt.exe: FORCE
$(MAKE) -C .. bitcoin_qt
apk: FORCE
$(MAKE) -C .. bitcoin_qt_apk
38 changes: 38 additions & 0 deletions src/qt/android/AndroidManifest.xml
@@ -0,0 +1,38 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest package="org.bitcoincore.qt" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<uses-sdk android:targetSdkVersion="24"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>

<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Bitcoin Core">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:name="org.bitcoincore.qt.BitcoinQtActivity"
android:label="Bitcoin Core"
android:icon="@drawable/bitcoin"
android:screenOrientation="unspecified"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data android:name="android.app.arguments" android:value="-testnet"/>
<meta-data android:name="android.app.lib_name" android:value="bitcoin-qt"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.system_libs_prefix" android:value="/system/lib/"/>
<meta-data android:name="android.app.background_running" android:value="true"/>
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="true"/>
<meta-data android:name="android.app.extract_android_style" android:value="default"/>
</activity>

</application>
</manifest>
52 changes: 52 additions & 0 deletions src/qt/android/build.gradle
@@ -0,0 +1,52 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}

repositories {
google()
jcenter()
}

apply plugin: 'com.android.application'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

android {
compileSdkVersion androidCompileSdkVersion.toInteger()

buildToolsVersion androidBuildToolsVersion

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}

lintOptions {
abortOnError false
}

dexOptions {
javaMaxHeapSize '4g'
}

defaultConfig {
minSdkVersion 24
}
}
4 changes: 4 additions & 0 deletions src/qt/android/gradle.properties
@@ -0,0 +1,4 @@
androidBuildToolsVersion=29.0.0-rc3
androidCompileSdkVersion=24
qt5AndroidDir=new File(".").absolutePath
org.gradle.jvmargs=-Xmx4608M
Binary file added src/qt/android/res/drawable-hdpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/android/res/drawable-ldpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/android/res/drawable-mdpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/android/res/drawable-xhdpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/android/res/drawable-xxhdpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/android/res/drawable-xxxhdpi/bitcoin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/qt/android/src/org/bitcoincore/qt/BitcoinQtActivity.java
@@ -0,0 +1,29 @@
package org.bitcoincore.qt;

import android.os.Bundle;
import android.system.ErrnoException;
import android.system.Os;

import org.qtproject.qt5.android.bindings.QtActivity;

import java.io.File;

public class BitcoinQtActivity extends QtActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
final File bitcoinDir = new File(getFilesDir().getAbsolutePath() + "/.bitcoin");
if (!bitcoinDir.exists()) {
bitcoinDir.mkdir();
}

try {
Os.setenv("QT_QPA_PLATFORM", "android", true);
} catch (ErrnoException e) {
e.printStackTrace();
}

super.onCreate(savedInstanceState);
}
}
7 changes: 7 additions & 0 deletions src/qt/bitcoin.cpp
Expand Up @@ -427,6 +427,13 @@ int GuiMain(int argc, char* argv[])

// Generate high-dpi pixmaps
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

#if defined(QT_QPA_PLATFORM_ANDROID)
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
#endif

#if QT_VERSION >= 0x050600
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Expand Down

0 comments on commit a818b2c

Please sign in to comment.