Skip to content

Commit

Permalink
Merge pull request #1258 from dg0yt
Browse files Browse the repository at this point in the history
Review APK naming, configuration and signing
  • Loading branch information
dg0yt authored Jun 10, 2019
2 parents 9193bd5 + 6dd6566 commit 56d8cce
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
41 changes: 23 additions & 18 deletions android/CPackConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 <keystore> --ks-key-alias <alias> ${apk}"
)
>
endif()


Expand Down Expand Up @@ -92,8 +101,10 @@ execute_process(
--deployment "bundled"
--gradle
--verbose
$<$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>:
$<@RELEASE_APK@:
--release
>
$<@SIGN_APK@:
${sign}
>
WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/Mapper"
Expand All @@ -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}")
Expand Down
8 changes: 4 additions & 4 deletions android/Mapper.pro.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ 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(/<manifest/ s/org.openorienteering.mapper/org.openorienteering.mapper.dev/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/AndroidManifest.xml")
system(sed -e $$shell_quote(s/%%INSERT_APP_NAME%% *-->/%%INSERT_APP_NAME%% --> dev/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/res/values/strings.xml")
system(sed -e $$shell_quote(/<manifest/ s/@Mapper_VERSION@/@Mapper_VERSION_DISPLAY@/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/AndroidManifest.xml")
system(sed -e $$shell_quote(s/%%INSERT_APP_NAME%% *-->/%%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--")
}

Expand Down
1 change: 0 additions & 1 deletion ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ jobs:
- $(TARGET)-toolchain-$(openorienteering.superbuild.ndkVersion)
- toolchain-info-$(TARGET)
- android-libcxx-armeabi-v7a-$(openorienteering.superbuild.ndkVersion)
outputFilter: packaging/Mapper/install/build/outputs/apk/*/*.apk
- template: publish.yml


Expand Down
12 changes: 11 additions & 1 deletion packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,20 @@ elseif(ANDROID)
"Alias in the keystore to be used when signing APK packages."
)
if(KEYSTORE_URL AND KEYSTORE_ALIAS)
set(SIGN_APK "$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>")
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"
Expand Down

0 comments on commit 56d8cce

Please sign in to comment.