From f73a91c0be1455b4698c22c13e9b3106e7f8b201 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Thu, 28 Sep 2023 13:44:18 +0800 Subject: [PATCH] Provide option to easily modify app name and version. Chery-picked from #243. --- app/build.gradle | 49 ++++++++++++++++++++++++++------ app/src/main/AndroidManifest.xml | 4 +-- gradle.properties | 37 +++++++++++------------- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d2662350..d2ad0400 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,18 +1,21 @@ +import java.nio.charset.StandardCharsets + plugins { id 'com.android.application' } android { namespace "org.love2d.android" - compileSdk 33 - ndkVersion "25.2.9519653" + ndkVersion "26.0.10792818" defaultConfig { - applicationId "org.love2d.android" - versionCode 32 - versionName "12.0" + applicationId project.properties["app.application_id"] + versionCode project.properties["app.version_code"].toInteger() + versionName project.properties["app.version_name"] minSdk 21 - targetSdk 33 + compileSdk 34 + targetSdk 34 + externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared" @@ -24,6 +27,30 @@ android { targets "love_android", "OpenAL", "love" } } + + def getAppName = { + def nameArray = project.properties["app.name_byte_array"] + def name = project.properties["app.name"] + if (name != null && nameArray != null) { + throw new Exception("Only define either `app.name` or `app.name_byte_array` in gradle.properties, but not both!") + } + + if (name == null) { + def nameArraySplit = nameArray.split(",") + def nameBytes = new byte[nameArraySplit.length] + def count = 0 + for (String s: nameArraySplit) { + nameBytes[count++] = (byte) Integer.parseInt(s) + } + return new String(nameBytes, StandardCharsets.UTF_8) + } + return name + } + + manifestPlaceholders = [ + NAME:getAppName(), + ORIENTATION:project.properties["app.orientation"], + ] } def retrieveAll3pModules = { -> @@ -33,6 +60,7 @@ android { if (details.isDirectory()) { if (file(details.file.path + "/Android.mk").exists() || file(details.file.path + "/CMakeLists.mk").exists()) { + def logger = project.getLogger() logger.lifecycle("3rd-party module: " + details.file.path) def javainfo = file(details.file.path + "/java.txt") @@ -71,7 +99,7 @@ android { prefab true } - flavorDimensions 'mode', 'recording' + flavorDimensions = ['mode', 'recording'] productFlavors { normal { dimension 'mode' @@ -123,7 +151,12 @@ android { } packagingOptions { jniLibs { - excludes += ['lib/armeabi-v7a/libOpenSLES.so', 'lib/arm64-v8a/libOpenSLES.so', 'lib/x86/libOpenSLES.so', 'lib/x86_64/libOpenSLES.so'] + excludes += [ + 'lib/armeabi-v7a/libOpenSLES.so', + 'lib/arm64-v8a/libOpenSLES.so', + 'lib/x86/libOpenSLES.so', + 'lib/x86_64/libOpenSLES.so' + ] } } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 255d1c52..d20fda71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ + android:label="${NAME}"> + android:screenOrientation="${ORIENTATION}"> diff --git a/gradle.properties b/gradle.properties index 193a5b26..f818faff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,22 +1,19 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn +# To set the application display name, only define either `app.name` or `app.name_byte_array`. +# For a rule of thumb: +# * Use `app.name` if your app name doesn't contain any non-ANSI characters. +# * Otherwise, convert your app name to UTF-8 byte array, comma delimited, and put +# it in `app.name_byte_array` +#app.name=LÖVE for Android +app.name_byte_array=76,195,150,86,69,32,102,111,114,32,65,110,100,114,111,105,100 + +app.application_id=org.love2d.android +app.orientation=landscape +app.version_code=32 +app.version_name=12.0 + +# No need to modify anything past this line! +android.enableJetifier=false android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true android.defaults.buildfeatures.buildconfig=true -android.nonTransitiveRClass=false -android.nonFinalResIds=false \ No newline at end of file +android.nonTransitiveRClass=true +android.nonFinalResIds=true