From 3942328e202dae85417a67a1d36512f91adb9f40 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Mon, 10 Jun 2019 11:51:07 +0200 Subject: [PATCH 1/2] Android: Inject version display name into Manifest --- android/Mapper.pro.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/Mapper.pro.in b/android/Mapper.pro.in index edc5efe83..bb6f42708 100644 --- a/android/Mapper.pro.in +++ b/android/Mapper.pro.in @@ -37,7 +37,8 @@ CONFIG(debug, release|debug) { system(cp -a "$$ANDROID_PACKAGE_SOURCE_DIR" "$$OUT_PWD/") ANDROID_PACKAGE_SOURCE_DIR = $$OUT_PWD/android system(sed -e $$shell_quote(//%%INSERT_APP_NAME%% --> dev/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/res/values/strings.xml") + system(sed -e $$shell_quote(//%%INSERT_APP_NAME%% --> @Mapper_VERSION_DISPLAY@/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/res/values/strings.xml") system(rm -f "$$ANDROID_PACKAGE_SOURCE_DIR/AndroidManifest.xml--" "$$ANDROID_PACKAGE_SOURCE_DIR/res/values/strings.xml--") } From 6dd65661fd9c44bb663778210bb5bdb382541845 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Mon, 10 Jun 2019 11:52:33 +0200 Subject: [PATCH 2/2] Android: Review APK naming, config and signing Separate signing configuration from release vs. debug configuration. Use 'dev' APK ID suffix for all builds with non standard version display string. Update instructions for manual signing. Last not least, always copy the APK to the standard file path where the regular CPack generators put the output. --- android/CPackConfig.cmake.in | 41 ++++++++++++++++++++---------------- android/Mapper.pro.in | 5 ++--- ci/azure-pipelines.yml | 1 - packaging/CMakeLists.txt | 12 ++++++++++- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/android/CPackConfig.cmake.in b/android/CPackConfig.cmake.in index 0b0ed9b4c..884504aaa 100644 --- a/android/CPackConfig.cmake.in +++ b/android/CPackConfig.cmake.in @@ -26,8 +26,16 @@ set(CPACK_GENERATOR "") set(destdir "@CMAKE_CURRENT_BINARY_DIR@/Mapper/install") set(final_message ) -set(KEYSTORE_URL "@KEYSTORE_URL@") -set(KEYSTORE_ALIAS "@KEYSTORE_ALIAS@") + +set(apk "${destdir}/build/outputs/apk/") +if(@RELEASE_APK@) + set(config "CONFIG+=release") + set(apk "${apk}/release/install-release" ) +else() + set(config "CONFIG+=debug") + set(apk "${apk}/debug/install-debug" ) +endif() + set(SIGN_APK "@SIGN_APK@") if(SIGN_APK AND "@CMAKE_HOST_UNIX@") execute_process(COMMAND "${CMAKE_COMMAND}" -E echo "Checking if we are running in a terminal") @@ -38,19 +46,20 @@ if(SIGN_APK AND "@CMAKE_HOST_UNIX@") set(SIGN_APK 0) endif() endif() + if(SIGN_APK) - set(config "CONFIG+=release") - set(sign --sign "${KEYSTORE_URL}" "${KEYSTORE_ALIAS}") + set(sign --sign "@KEYSTORE_URL@" "@KEYSTORE_ALIAS@") + set(apk "${apk}-signed.apk" ) else() - set(config "CONFIG+=debug") set(sign ) -$<@SIGN_APK@: - # APK signing enabled at configuration time, but disabled at build time. + if(@RELEASE_APK@) + set(apk "${apk}-unsigned.apk") + else() + set(apk "${apk}.apk") + endif() set(final_message "The build created an unsigned APK. To sign the APK, run: - jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore '${KEYSTORE_URL}' /path/to/install-release-unsigned.apk '${KEYSTORE_ALIAS}' - zipalign 4 /path/to/install-release-unsigned.apk outfile.apk" + apksigner sign --ks --ks-key-alias ${apk}" ) -> endif() @@ -92,8 +101,10 @@ execute_process( --deployment "bundled" --gradle --verbose -$<$,$>: +$<@RELEASE_APK@: --release +> +$<@SIGN_APK@: ${sign} > WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/Mapper" @@ -103,13 +114,7 @@ if(result) message(FATAL_ERROR "Running androiddeployqt failed: ${result}") endif() -if(SIGN_APK) - configure_file( - "@CMAKE_CURRENT_BINARY_DIR@/Mapper/install/build/outputs/apk/install-release-signed.apk" - "@PROJECT_BINARY_DIR@/@CPACK_PACKAGE_FILE_NAME@.apk" - COPYONLY - ) -endif() +configure_file("${apk}" "@PROJECT_BINARY_DIR@/@CPACK_PACKAGE_FILE_NAME@.apk" COPYONLY) if(final_message) message(STATUS "${final_message}") diff --git a/android/Mapper.pro.in b/android/Mapper.pro.in index bb6f42708..fd14ef75c 100644 --- a/android/Mapper.pro.in +++ b/android/Mapper.pro.in @@ -31,9 +31,8 @@ EXPECTED_VERSION = @Mapper_VERSION_MAJOR@\.@Mapper_VERSION_MINOR@\.@Mapper_VERSI error(The version name in AndroidManifest.xml does not match $$EXPECTED_VERSION.) } -CONFIG(debug, release|debug) { - # Don't let (unsigned) debug packages replace (signed) release packages, - # or the developer may loose maps. +@USE_DEV_SUFFIX@ { + # Don't let unstable packages replace official release packages. system(cp -a "$$ANDROID_PACKAGE_SOURCE_DIR" "$$OUT_PWD/") ANDROID_PACKAGE_SOURCE_DIR = $$OUT_PWD/android system(sed -e $$shell_quote(/,$>") + set(SIGN_APK 1) else() set(SIGN_APK 0) endif() + if("@CMAKE_BUILD_TYPE@" MATCHES "Rel") + set(RELEASE_APK 1) + else() + set(RELEASE_APK 0) + endif() + if("${Mapper_VERSION_DISPLAY}" STREQUAL "${Mapper_VERSION}") + set(USE_DEV_SUFFIX "false") + else() + set(USE_DEV_SUFFIX "true") + endif() configure_file( "${PROJECT_SOURCE_DIR}/android/CPackConfig.cmake.in" "${PROJECT_BINARY_DIR}/CPackConfig.tmp.cmake"