From 034bcf4f442a7b30278b171e4e884725d30bcaa1 Mon Sep 17 00:00:00 2001 From: gd <gd@iotide.com> Date: Tue, 4 Feb 2025 10:22:17 +0200 Subject: [PATCH] android: added product flavors to separatly build apk for arm64-v8a or x86_64 --- android/README.md | 12 +++++++----- android/app/build.gradle.kts | 24 ++++++++++++++++++------ android/build.py | 8 ++++++++ doc/user.rst | 7 +++++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/android/README.md b/android/README.md index 371a0a1b6..44d93b22c 100644 --- a/android/README.md +++ b/android/README.md @@ -2,11 +2,14 @@ Notes and resources for MPD android maintainers. +## Build + +See [Compiling for Android](https://github.com/MusicPlayerDaemon/MPD/blob/45cb098cd765af12316f8dca5635ef10a852e013/doc/user.rst#compiling-for-android) + ## Android studio ### Version control - git ignoring .idea directory completely until a good reason emerges not to * [How to manage projects under Version Control Systems (jetbrains.com)](https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems) @@ -17,10 +20,9 @@ git ignoring .idea directory completely until a good reason emerges not to * [Include prebuilt native libraries (developer.android.com)](https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs) +## Permissions -### Permissions - -#### Files access +### Files access The required permission depends on android SDK version: @@ -29,7 +31,7 @@ The required permission depends on android SDK version: else Manifest.permission.READ_EXTERNAL_STORAGE -#### Permission request +### Permission request [Request runtime permissions](https://developer.android.com/training/permissions/requesting) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 531795391..2f2dbb96e 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -18,11 +18,6 @@ android { vectorDrawables { useSupportLibrary = true } - ndk { - // Specifies the ABI configurations of your native - // libraries Gradle should build and package with your app. - abiFilters += "arm64-v8a" - } } buildFeatures { @@ -46,12 +41,29 @@ android { ) } } + // flavors + flavorDimensions += "base" + productFlavors { + create("arm64-v8a") { + ndk { + // ABI to include in package + //noinspection ChromeOsAbiSupport + abiFilters += listOf("arm64-v8a") + } + } + create("x86_64") { + ndk { + // ABI to include in package + abiFilters += listOf("x86_64") + } + } + } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_9 targetCompatibility = JavaVersion.VERSION_1_9 } kotlinOptions { - jvmTarget = "9" + jvmTarget = JavaVersion.VERSION_1_9.toString() } packaging { resources { diff --git a/android/build.py b/android/build.py index 69ac74730..5a74c4009 100755 --- a/android/build.py +++ b/android/build.py @@ -70,3 +70,11 @@ ninja = shutil.which("ninja") subprocess.check_call([ninja], env=toolchain.env) subprocess.check_call([ninja, 'install'], env=toolchain.env) + +print(""" +------------------------------------- +## To build the android app: +# cd ../../android +# ./gradlew assemble{}Debug +------------------------------------- +""".format(android_abi.capitalize())) \ No newline at end of file diff --git a/doc/user.rst b/doc/user.rst index b0a4de521..e76d8e8a5 100644 --- a/doc/user.rst +++ b/doc/user.rst @@ -223,11 +223,14 @@ tarball and change into the directory. Then, instead of -Dwrap_mode=forcefallback \ -Dandroid_debug_keystore=$HOME/.android/debug.keystore cd ../../android - ./gradlew assembleDebug + ./gradlew assemble{ABI}Debug + +In the argument to `gradlew`, replace `{ABI}` with the build ABI. +The `productFlavor` names defined in `build.android.kts` match the ABI. :envvar:`SDK_PATH` is the absolute path where you installed the Android SDK; :envvar:`NDK_PATH` is the Android NDK installation path; -ABI is the Android ABI to be built, e.g. ":code:`arm64-v8a`". +ABI is the Android ABI to be built, e.g. ":code:`x86`, `x86_64`, `armeabi`, `armeabi-v7a`, `arm64-v8a`". This downloads various library sources, and then configures and builds :program:`MPD`.