From 4dcf0b8ae0569beaf615fc19df2147bfb1597046 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 18 Feb 2014 08:33:06 +0100 Subject: [PATCH] first Android release Finally, MPD runs on Android. For some small value of "runs". Very much work left, too much to describe. --- Makefile.am | 52 +++++- NEWS | 1 + android/.gitignore | 1 + android/AndroidManifest.xml | 24 +++ android/build.py | 300 +++++++++++++++++++++++++++++++++ android/custom_rules.xml | 11 ++ android/res/drawable/icon.png | Bin 0 -> 2931 bytes android/res/values/strings.xml | 5 + android/src/Bridge.java | 27 +++ android/src/Loader.java | 39 +++++ android/src/Main.java | 62 +++++++ configure.ac | 21 +++ src/Main.cxx | 19 +++ 13 files changed, 559 insertions(+), 3 deletions(-) create mode 100644 android/.gitignore create mode 100644 android/AndroidManifest.xml create mode 100755 android/build.py create mode 100644 android/custom_rules.xml create mode 100644 android/res/drawable/icon.png create mode 100644 android/res/values/strings.xml create mode 100644 android/src/Bridge.java create mode 100644 android/src/Loader.java create mode 100644 android/src/Main.java diff --git a/Makefile.am b/Makefile.am index 7e05cd375..c02ca7ce7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,10 @@ AM_CPPFLAGS += -I$(srcdir)/src $(GLIB_CFLAGS) AM_CPPFLAGS += -DSYSTEM_CONFIG_FILE_LOCATION='"$(sysconfdir)/mpd.conf"' +if ANDROID +else bin_PROGRAMS = src/mpd +endif noinst_LIBRARIES = \ libmpd.a \ @@ -24,6 +27,8 @@ noinst_LIBRARIES = \ libmixer_plugins.a \ liboutput_plugins.a +libmpd_a_DEPENDENCIES = + libmpd_a_CPPFLAGS = $(AM_CPPFLAGS) \ $(LIBMPDCLIENT_CFLAGS) \ $(AVAHI_CFLAGS) \ @@ -238,9 +243,50 @@ UPNP_SOURCES = \ # if ANDROID -all-local: libmpd.so -libmpd.so: $(filter %.a,$(src_mpd_LDADD)) - $(AM_V_CXXLD)$(CXXLD) -Wl,-shared -o $@ $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) $(src_mpd_LDADD) $(LIBS) + +noinst_LIBRARIES += libmain.a +libmain_a_SOURCES = \ + src/Main.cxx src/Main.hxx +libmain_a_CPPFLAGS = $(AM_CPPFLAGS) -Iandroid/build/include + +all-local: android/build/bin/Main-debug.apk +clean-local: + rm -rf android/build + +libmpd.so: $(filter %.a,$(src_mpd_LDADD)) libmain.a + $(AM_V_CXXLD)$(CXXLD) -shared -Wl,--no-undefined,-shared,-Bsymbolic -llog -lz -o $@ $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) src/libmain_a-Main.o $(src_mpd_LDADD) $(LIBS) + +android/build/build.xml: android/AndroidManifest.xml + rm -rf android/build + mkdir -p android/build/include + ln -s $(srcdir)/android/AndroidManifest.xml $(srcdir)/android/custom_rules.xml $(srcdir)/android/src $(srcdir)/android/res android/build + $(ANDROID_SDK)/tools/android update project --path android/build --target android-9 + +android/build/bin/classes/org/musicpd/Bridge.class: android/src/Bridge.java android/build/build.xml + cd android/build && ant compile-jni-classes + +android/build/include/org_musicpd_Bridge.h: android/build/bin/classes/org/musicpd/Bridge.class + javah -classpath $(ANDROID_SDK)/platforms/android-17/android.jar:android/build/bin/classes -d $(@D) org.musicpd.Bridge + +libmpd_a_DEPENDENCIES += android/build/include/org_musicpd_Bridge.h + +android/build/libs/armeabi-v7a/libmpd.so: libmpd.so android/build/build.xml + mkdir -p $(@D) + rm -f $@ + strip -o $@ $< + +android/build/bin/Main-debug.apk: android/build/build.xml android/build/libs/armeabi-v7a/libmpd.so + cd android/build && ant nodeps debug + +android/build/bin/Main-release-unsigned.apk: android/build/build.xml android/build/libs/armeabi-v7a/libmpd.so + cd android/build && ant nodeps release + +android/build/bin/Main-release-unaligned.apk: android/build/bin/Main-release-unsigned.apk + jarsigner -digestalg SHA1 -sigalg MD5withRSA -storepass:env ANDROID_KEYSTORE_PASS -keystore $(ANDROID_KEYSTORE) -signedjar $@ $< $(ANDROID_KEY_ALIAS) + +android/build/bin/Main.apk: android/build/bin/Main-release-unaligned.apk + $(ANDROID_SDK)/tools/zipalign -f 4 $< $@ + endif # diff --git a/NEWS b/NEWS index 25a1d1dd7..3883a51e3 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ ver 0.19 (not yet released) * new resampler option using libsoxr * allow playlist directory without music directory * install systemd unit for socket activation +* Android port ver 0.18.9 (not yet released) * decoder diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/android/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml new file mode 100644 index 000000000..6daa0e5f3 --- /dev/null +++ b/android/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/android/build.py b/android/build.py new file mode 100755 index 000000000..c89baf216 --- /dev/null +++ b/android/build.py @@ -0,0 +1,300 @@ +#!/usr/bin/env python3 + +import os.path +import sys, shutil, subprocess +import urllib.request +import hashlib +import re + +if len(sys.argv) < 3: + print("Usage: build.py SDK_PATH NDK_PATH [configure_args...]", file=sys.stderr) + sys.exit(1) + +sdk_path = sys.argv[1] +ndk_path = sys.argv[2] +configure_args = sys.argv[3:] + +if not os.path.isfile(os.path.join(sdk_path, 'tools', 'android')): + print("SDK not found in", ndk_path, file=sys.stderr) + sys.exit(1) + +if not os.path.isdir(ndk_path): + print("NDK not found in", ndk_path, file=sys.stderr) + sys.exit(1) + +# the path to the MPD sources +mpd_path = os.path.dirname(os.path.dirname(sys.argv[0])) + +# output directories +lib_path = os.path.abspath('lib') +tarball_path = lib_path +src_path = os.path.join(lib_path, 'src') +build_path = os.path.join(lib_path, 'build') +root_path = os.path.join(lib_path, 'root') + +# build host configuration +build_arch = 'linux-x86_64' + +# redirect pkg-config to use our root directory instead of the default +# one on the build host +os.environ['PKG_CONFIG_LIBDIR'] = os.path.join(root_path, 'lib/pkgconfig') + +# select the NDK compiler +gcc_version = '4.8' +llvm_version = '3.3' + +# select the NDK target +ndk_arch = 'arm' +host_arch = 'arm-linux-androideabi' +android_abi = 'armeabi-v7a' +ndk_platform = 'android-14' + +# set up the NDK toolchain + +gcc_toolchain = os.path.join(ndk_path, 'toolchains', host_arch + '-' + gcc_version, 'prebuilt', build_arch) +llvm_toolchain = os.path.join(ndk_path, 'toolchains', 'llvm-' + llvm_version, 'prebuilt', build_arch) +ndk_platform_path = os.path.join(ndk_path, 'platforms', ndk_platform) +target_root = os.path.join(ndk_platform_path, 'arch-' + ndk_arch) + +llvm_triple = 'armv7-none-linux-androideabi' + +def select_toolchain(use_cxx, use_clang): + global cc, cxx, ar, cflags, cxxflags, cppflags, ldflags, libs + + target_arch = '-march=armv7-a -mfloat-abi=softfp' + if use_clang: + cc = os.path.join(llvm_toolchain, 'bin/clang') + cxx = os.path.join(llvm_toolchain, 'bin/clang++') + target_arch += ' -target ' + llvm_triple + ' -integrated-as -gcc-toolchain ' + gcc_toolchain + else: + cc = os.path.join(gcc_toolchain, 'bin', host_arch + '-gcc') + cxx = os.path.join(gcc_toolchain, 'bin', host_arch + '-g++') + ar = os.path.join(gcc_toolchain, 'bin', host_arch + '-ar') + + libstdcxx_path = os.path.join(ndk_path, 'sources/cxx-stl/gnu-libstdc++', gcc_version) + libstdcxx_cppflags = '-isystem ' + os.path.join(libstdcxx_path, 'include') + ' -isystem ' + os.path.join(libstdcxx_path, 'libs', android_abi, 'include') + if use_clang: + libstdcxx_cppflags += ' -D__STRICT_ANSI__' + libstdcxx_ldadd = os.path.join(libstdcxx_path, 'libs', android_abi, 'libgnustl_static.a') + + cflags = '-Os -g ' + target_arch + cxxflags = '-Os -g ' + target_arch + cppflags = '--sysroot=' + target_root + ldflags = '--sysroot=' + target_root + libs = '' + + if use_cxx: + libs += ' ' + libstdcxx_ldadd + cppflags += ' ' + libstdcxx_cppflags + +def file_md5(path): + """Calculate the MD5 checksum of a file and return it in hexadecimal notation.""" + + with open(path, 'rb') as f: + m = hashlib.md5() + while True: + data = f.read(65536) + if len(data) == 0: + # end of file + return m.hexdigest() + m.update(data) + +def download_tarball(url, md5): + """Download a tarball, verify its MD5 checksum and return the local path.""" + + global tarball_path + os.makedirs(tarball_path, exist_ok=True) + path = os.path.join(tarball_path, os.path.basename(url)) + + try: + calculated_md5 = file_md5(path) + if md5 == calculated_md5: return path + os.unlink(path) + except FileNotFoundError: + pass + + tmp_path = path + '.tmp' + + print("download", url) + urllib.request.urlretrieve(url, tmp_path) + calculated_md5 = file_md5(tmp_path) + if calculated_md5 != md5: + os.unlink(tmp_path) + raise "MD5 mismatch" + + os.rename(tmp_path, path) + return path + +class Project: + def __init__(self, url, md5, installed, name=None, version=None, + use_cxx=False, use_clang=False): + basename = os.path.basename(url) + m = re.match(r'^(.+)\.(tar(\.(gz|bz2|xz|lzma))?|zip)$', basename) + if not m: raise + self.base = m.group(1) + + if name is None or version is None: + m = re.match(r'^([-\w]+)-(\d[\d.]*)$', self.base) + if name is None: name = m.group(1) + if version is None: version = m.group(2) + + self.name = name + self.version = version + + self.url = url + self.md5 = md5 + self.installed = installed + + self.use_cxx = use_cxx + self.use_clang = use_clang + + def download(self): + return download_tarball(self.url, self.md5) + + def is_installed(self): + global root_path + tarball = self.download() + installed = os.path.join(root_path, self.installed) + tarball_mtime = os.path.getmtime(tarball) + try: + return os.path.getmtime(installed) >= tarball_mtime + except FileNotFoundError: + return False + + def unpack(self): + global src_path + tarball = self.download() + path = os.path.join(src_path, self.base) + try: + shutil.rmtree(path) + except FileNotFoundError: + pass + os.makedirs(src_path, exist_ok=True) + subprocess.check_call(['/bin/tar', 'xfC', tarball, src_path]) + return path + + def make_build_path(self): + path = os.path.join(build_path, self.base) + try: + shutil.rmtree(path) + except FileNotFoundError: + pass + os.makedirs(path, exist_ok=True) + return path + +class AutotoolsProject(Project): + def __init__(self, url, md5, installed, configure_args=[], **kwargs): + Project.__init__(self, url, md5, installed, **kwargs) + self.configure_args = configure_args + + def build(self): + src = self.unpack() + build = self.make_build_path() + + select_toolchain(use_cxx=self.use_cxx, use_clang=self.use_clang) + configure = [ + os.path.join(src, 'configure'), + 'CC=' + cc, + 'CXX=' + cxx, + 'CFLAGS=' + cflags, + 'CXXFLAGS=' + cxxflags, + 'CPPFLAGS=' + cppflags, + 'LDFLAGS=' + ldflags, + 'LIBS=' + libs, + 'AR=' + ar, + '--host=' + host_arch, + '--prefix=' + root_path, + '--with-sysroot=' + target_root, + '--enable-silent-rules', + ] + self.configure_args + + subprocess.check_call(configure, cwd=build) + subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], cwd=build) + subprocess.check_call(['/usr/bin/make', '--quiet', 'install'], cwd=build) + +# a list of third-party libraries to be used by MPD on Android +thirdparty_libs = [ + AutotoolsProject( + 'http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.xz', + 'ca25d8da0ddfc8c6cbbf78d847a209fe', + 'lib/libogg.a', + ['--disable-shared', '--enable-static'], + ), + + AutotoolsProject( + 'http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.xz', + '55f2288055e44754275a17c9a2497391', + 'lib/libvorbis.a', + ['--disable-shared', '--enable-static'], + ), + + AutotoolsProject( + 'https://svn.xiph.org/releases/flac/flac-1.3.0.tar.xz', + '13b5c214cee8373464d3d65dee362cdd', + 'lib/libFLAC.a', + [ + '--disable-shared', '--enable-static', + '--disable-xmms-plugin', '--disable-cpplibs', + ], + use_clang=True, + ), + + AutotoolsProject( + 'http://curl.haxx.se/download/curl-7.35.0.tar.lzma', + 'ad7d63864414c61246450dc5e2248c7b', + 'lib/libcurl.a', + [ + '--disable-shared', '--enable-static', + '--disable-debug', + '--enable-http', + '--enable-ipv6', + '--disable-ftp', '--disable-file', + '--disable-ldap', '--disable-ldaps', + '--disable-rtsp', '--disable-proxy', '--disable-dict', '--disable-telnet', + '--disable-tftp', '--disable-pop3', '--disable-imap', '--disable-smtp', + '--disable-gopher', + '--disable-manual', + '--disable-threaded-resolver', '--disable-verbose', '--disable-sspi', + '--disable-crypto-auth', '--disable-ntlm-wb', '--disable-tls-srp', '--disable-cookies', + '--without-ssl', '--without-gnutls', '--without-nss', '--without-libssh2', + ], + use_clang=True, + ), +] + +# build the third-party libraries +for x in thirdparty_libs: + if not x.is_installed(): + x.build() + +# configure and build MPD +select_toolchain(use_cxx=True, use_clang=True) + +configure = [ + os.path.join(mpd_path, 'configure'), + 'CC=' + cc, + 'CXX=' + cxx, + 'CFLAGS=' + cflags, + 'CXXFLAGS=' + cxxflags, + 'CPPFLAGS=' + cppflags, + 'LDFLAGS=' + ldflags, + 'LIBS=' + libs, + 'AR=' + ar, + '--host=' + host_arch, + '--prefix=' + root_path, + '--with-sysroot=' + target_root, + '--with-android-sdk=' + sdk_path, + + '--enable-silent-rules', + + '--disable-glib', + + # disabled for now because these features require GLib: + '--disable-database', + '--disable-httpd-output', + '--disable-vorbis-encoder', + +] + configure_args + +subprocess.check_call(configure) +subprocess.check_call(['/usr/bin/make', '--quiet', '-j12']) diff --git a/android/custom_rules.xml b/android/custom_rules.xml new file mode 100644 index 000000000..68db46590 --- /dev/null +++ b/android/custom_rules.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/android/res/drawable/icon.png b/android/res/drawable/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dd23fb895d79ca132e719368451b123b85da001f GIT binary patch literal 2931 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 XM*M$*7ndL(jR4#>GKbX~x;*|5XbEu4 literal 0 HcmV?d00001 diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml new file mode 100644 index 000000000..416c8de9f --- /dev/null +++ b/android/res/values/strings.xml @@ -0,0 +1,5 @@ + + + + MPD + diff --git a/android/src/Bridge.java b/android/src/Bridge.java new file mode 100644 index 000000000..d1dfec894 --- /dev/null +++ b/android/src/Bridge.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.musicpd; + +/** + * Bridge to native code. + */ +public class Bridge { + public static native void run(); +} diff --git a/android/src/Loader.java b/android/src/Loader.java new file mode 100644 index 000000000..6cbfeb4f2 --- /dev/null +++ b/android/src/Loader.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.musicpd; + +import android.util.Log; + +public class Loader { + private static final String TAG = "MPD"; + + public static boolean loaded = false; + public static String error; + + static { + try { + System.loadLibrary("mpd"); + loaded = true; + } catch (UnsatisfiedLinkError e) { + Log.e(TAG, e.getMessage()); + error = e.getMessage(); + } + } +} diff --git a/android/src/Main.java b/android/src/Main.java new file mode 100644 index 000000000..01974af6d --- /dev/null +++ b/android/src/Main.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.musicpd; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; +import android.os.Build; +import android.util.Log; + +public class Main extends Activity implements Runnable { + private static final String TAG = "MPD"; + + Thread thread; + + @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (!Loader.loaded) { + TextView tv = new TextView(this); + tv.setText("Failed to load the native MPD libary.\n" + + "Report this problem to us, and include the following information:\n" + + "ABI=" + Build.CPU_ABI + "\n" + + "PRODUCT=" + Build.PRODUCT + "\n" + + "FINGERPRINT=" + Build.FINGERPRINT + "\n" + + "error=" + Loader.error); + setContentView(tv); + return; + } + + if (thread == null || !thread.isAlive()) { + thread = new Thread(this, "NativeMain"); + thread.start(); + } + + TextView tv = new TextView(this); + tv.setText("Music Player Daemon is running" + + "\nCAUTION: this version is EXPERIMENTAL!"); + setContentView(tv); + } + + @Override public void run() { + Bridge.run(); + } +} diff --git a/configure.ac b/configure.ac index c0aa04c58..f05c17b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -152,6 +152,27 @@ if test -z "$prefix" || test "x$prefix" = xNONE; then done fi +dnl --------------------------------------------------------------------------- +dnl Android +dnl --------------------------------------------------------------------------- + +AC_ARG_WITH([android-sdk], + AS_HELP_STRING([--with-android-sdk=DIR], + [Directory for Android SDK]), + [], [with_android_sdk=no]) + +if test x$host_is_android = xyes; then + if test x$with_android_sdk = xno; then + AC_MSG_ERROR([Android build requires option --with-android-sdk=DIR]) + fi + + if ! test -x $with_android_sdk/tools/android; then + AC_MSG_ERROR([Android SDK not found in $with_android_sdk]) + fi +fi + +AC_SUBST(ANDROID_SDK, [$with_android_sdk]) + dnl --------------------------------------------------------------------------- dnl Language Checks dnl --------------------------------------------------------------------------- diff --git a/src/Main.cxx b/src/Main.cxx index fb2aaf0a9..be7c07272 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -88,6 +88,10 @@ #include "archive/ArchiveList.hxx" #endif +#ifdef ANDROID +#include "org_musicpd_Bridge.h" +#endif + #ifdef HAVE_GLIB #include #endif @@ -365,6 +369,8 @@ shutdown_event_emitted(void) #endif +#ifndef ANDROID + int main(int argc, char *argv[]) { #ifdef WIN32 @@ -374,6 +380,8 @@ int main(int argc, char *argv[]) #endif } +#endif + int mpd_main(int argc, char *argv[]) { struct options options; @@ -646,3 +654,14 @@ int mpd_main(int argc, char *argv[]) log_deinit(); return EXIT_SUCCESS; } + +#ifdef ANDROID + +gcc_visibility_default +JNIEXPORT void JNICALL +Java_org_musicpd_Bridge_run(JNIEnv *, jclass) +{ + mpd_main(0, nullptr); +} + +#endif