Skip to content

Commit

Permalink
Android: Review APK naming, config and signing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dg0yt committed Jun 10, 2019
1 parent 3942328 commit 6dd6566
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 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
5 changes: 2 additions & 3 deletions android/Mapper.pro.in
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<manifest/ s/org.openorienteering.mapper/org.openorienteering.mapper.dev/) -i -- "$$ANDROID_PACKAGE_SOURCE_DIR/AndroidManifest.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 6dd6566

Please sign in to comment.