Browse Source

Merge pull request #6082 from kambala-decapitator/android-improvements

Android improvements
Ivan Savenko 1 month ago
parent
commit
c558b3e683

+ 1 - 3
CMakeLists.txt

@@ -736,9 +736,7 @@ if(ANDROID)
 
 	if(ANDROID_STL MATCHES "_shared$")
 		set(stlLibName "${CMAKE_SHARED_LIBRARY_PREFIX}${ANDROID_STL}${CMAKE_SHARED_LIBRARY_SUFFIX}")
-		install(FILES "${CMAKE_SYSROOT}/usr/lib/${ANDROID_SYSROOT_LIB_SUBDIR}/${stlLibName}"
-			DESTINATION ${LIB_DIR}
-		)
+		vcmi_install_libs_symlink("${CMAKE_SYSROOT}/usr/lib/${ANDROID_SYSROOT_LIB_SUBDIR}/${stlLibName}")
 	endif()
 else()
 	install(DIRECTORY config DESTINATION ${DATA_DIR})

+ 4 - 2
android/AndroidManifest.xml

@@ -31,7 +31,9 @@
 		android:label="${applicationLabel}"
 		android:testOnly="false"
 		android:supportsRtl="true"
-		android:usesCleartextTraffic="false">
+		android:usesCleartextTraffic="false"
+		android:theme="@style/AppTheme"
+	>
 		<activity
 			android:name=".ActivityLauncher"
 			android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
@@ -42,7 +44,7 @@
 				<category android:name="android.intent.category.LAUNCHER"/>
 			</intent-filter>
 
-			<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts${applicationVariant}" /> 
+			<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" /> 
 
 			<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
 			<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>

+ 4 - 0
android/build.gradle

@@ -3,9 +3,13 @@ buildscript {
 	repositories {
 		google()
 		mavenCentral()
+		maven {
+			url 'https://www.jitpack.io'
+		}
 	}
 	dependencies {
 		classpath 'com.android.tools.build:gradle:8.11.0'
+		classpath 'com.github.zellius:android-shortcut-gradle-plugin:0.1.2'
 
 		// NOTE: Do not place your application dependencies here; they belong
 		// in the individual module build.gradle files

+ 0 - 1
android/vcmi-app/src/main/res/xml/shortcuts.xml → android/shortcuts.xml

@@ -7,7 +7,6 @@
 		android:shortcutLongLabel="@string/shortcut_play">
 		<intent
 			android:action="android.intent.action.VIEW"
-			android:targetPackage="is.xyz.vcmi"
 			android:targetClass="eu.vcmi.vcmi.VcmiSDLActivity" />
 	</shortcut>
 </shortcuts>

+ 9 - 4
android/vcmi-app/build.gradle

@@ -1,4 +1,5 @@
 apply plugin: 'com.android.application'
+apply plugin: 'com.github.zellius.shortcut-helper'
 
 android {
 	/*******************************************************
@@ -36,8 +37,6 @@ android {
 
 		versionCode 1700
 		versionName "1.7.0"
-
-		setProperty("archivesBaseName", "vcmi")
 	}
 
 	sourceSets {
@@ -102,6 +101,9 @@ android {
 	}
 }
 
+base.archivesName = "vcmi"
+shortcutHelper.filePath = "../shortcuts.xml"
+
 def SigningPropertiesPath(final basePath, final signingConfigKey) {
 	return file("${basePath}/${signingConfigKey}.properties")
 }
@@ -147,6 +149,9 @@ def LoadSigningConfig(final signingConfigKey) {
 
 dependencies {
 	implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar'])
-	implementation 'androidx.annotation:annotation:1.7.1'
-	implementation 'androidx.documentfile:documentfile:1.0.1'
+	implementation('androidx.annotation:annotation:1.9.1')
+
+	// later versions require API level 21
+	implementation('androidx.appcompat:appcompat:1.6.1')
+	implementation('androidx.documentfile:documentfile:1.0.1')
 }

+ 7 - 0
android/vcmi-app/src/main/res/values-v21/styles.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+	<style name="AppTheme" parent="@style/Theme.AppCompat.DayNight.NoActionBar">
+		<!-- for Android 15 + SDK 35 -->
+		<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
+	</style>
+</resources>

+ 4 - 0
android/vcmi-app/src/main/res/values/styles.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+	<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar" />
+</resources>

+ 0 - 13
android/vcmi-app/src/main/res/xml/shortcutsdaily.xml

@@ -1,13 +0,0 @@
-<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
-	<shortcut
-		android:shortcutId="play"
-		android:enabled="true"
-		android:icon="@mipmap/ic_launcher"
-		android:shortcutShortLabel="@string/shortcut_play"
-		android:shortcutLongLabel="@string/shortcut_play">
-		<intent
-			android:action="android.intent.action.VIEW"
-			android:targetPackage="is.xyz.vcmi.daily"
-			android:targetClass="eu.vcmi.vcmi.VcmiSDLActivity" />
-	</shortcut>
-</shortcuts>

+ 0 - 13
android/vcmi-app/src/main/res/xml/shortcutsdebug.xml

@@ -1,13 +0,0 @@
-<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
-	<shortcut
-		android:shortcutId="play"
-		android:enabled="true"
-		android:icon="@mipmap/ic_launcher"
-		android:shortcutShortLabel="@string/shortcut_play"
-		android:shortcutLongLabel="@string/shortcut_play">
-		<intent
-			android:action="android.intent.action.VIEW"
-			android:targetPackage="is.xyz.vcmi.debug"
-			android:targetClass="eu.vcmi.vcmi.VcmiSDLActivity" />
-	</shortcut>
-</shortcuts>

+ 17 - 1
cmake_modules/VCMIUtils.cmake

@@ -118,6 +118,18 @@ function(vcmi_print_git_commit_hash)
 
 endfunction()
 
+# install(FILES) of shared libs but using symlink instead of copying
+function(vcmi_install_libs_symlink libs)
+	install(CODE "
+		foreach(lib ${libs})
+			cmake_path(GET lib FILENAME filename)
+			file(CREATE_LINK \${lib} \"\${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/\${filename}\"
+				COPY_ON_ERROR SYMBOLIC
+			)
+		endforeach()
+	")
+endfunction()
+
 # install dependencies from Conan, CONAN_RUNTIME_LIBS_FILE is set in conanfile.py
 function(vcmi_install_conan_deps)
 	if(NOT USING_CONAN)
@@ -125,7 +137,11 @@ function(vcmi_install_conan_deps)
 	endif()
 
 	file(STRINGS "${CONAN_RUNTIME_LIBS_FILE}" runtimeLibs)
-	install(FILES ${runtimeLibs} DESTINATION ${LIB_DIR})
+	if(ANDROID)
+		vcmi_install_libs_symlink("${runtimeLibs}")
+	else()
+		install(FILES ${runtimeLibs} DESTINATION ${LIB_DIR})
+	endif()
 endfunction()
 
 function(vcmi_deploy_qt deployQtToolName deployQtOptions)