Skip to content

Commit

Permalink
Fix Android App Bundle (.aab) signing. (#35)
Browse files Browse the repository at this point in the history
Fix the bug, which overrode the exported signed build artifact's ($BITRISE_SIGNED_APK_PATH) extension to `.apk` even if it was a `.abb`.
  • Loading branch information
BirmacherAkos authored Nov 9, 2018
1 parent f743683 commit 80363a9
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 142 deletions.
120 changes: 64 additions & 56 deletions bitrise.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
format_version: 5
format_version: 6
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

app:
Expand All @@ -9,7 +9,6 @@ app:

- SAMPLE_APP_REPOSITORY_URL: https://github.com/bitrise-samples/sample-apps-android-abi-split.git
- BRANCH: master
- GRADLE_TASK: assembleRelease
- GRADLEW_PATH: "./gradlew"

# define these in your .bitrise.secrets.yml
Expand All @@ -24,63 +23,32 @@ workflows:
ci:
before_run:
- audit-this-step
- _go_tests
- create_test_apk
steps:
- path::./:
is_skippable: true
title: Step Test - keystore pass == key pass
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_1_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_1
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_1
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_1
- path::./:
is_skippable: true
title: Step Test - keystore pass != key pass
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_2_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_2
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_2
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_2
- path::./:
is_skippable: true
title: Step Test - default alias
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_3_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_3
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_3
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_3
- path::./:
is_skippable: true
title: Step Test - android studio generated keystore (jks)
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_4_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_4
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_4
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_4
- go-list:
- golint:
- errcheck:
- go-test:
after_run:
- test_apk
- test_bundle

test:
before_run:
- audit-this-step
- _go_tests
- create_test_apk
steps:
- script:
inputs:
- content: |-
echo "BITRISE_APK_PATH: $BITRISE_APK_PATH"
- path::./:
title: Step Test
inputs:
- apk_path: $BITRISE_APK_PATH_LIST
- script:
inputs:
- content: |-
echo "BITRISE_SIGNED_APK_PATH: $BITRISE_SIGNED_APK_PATH"
echo "BITRISE_APK_PATH: $BITRISE_APK_PATH"
test_apk:
envs:
- GRADLE_TASK: assembleRelease
- APK_FILE_INCLUDE_FILTER: "*.apk"
after_run:
- create_build_artifact
- test

test_bundle:
envs:
- GRADLE_TASK: bundleRelease
- APK_FILE_INCLUDE_FILTER: "*.aab"
after_run:
- create_build_artifact
- test

create_test_apk:
create_build_artifact:
steps:
- script:
inputs:
Expand Down Expand Up @@ -112,10 +80,50 @@ workflows:
git remote add origin "${SAMPLE_APP_REPOSITORY_URL}"
git fetch || exit 1
[[ -n "${COMMIT}" ]] && git checkout "${COMMIT}" || git checkout "${BRANCH}"
- [email protected]:
inputs:
- ndk_revision: '16'
run_if: ".IsCI"
- gradle-runner:
inputs:
- gradle_task: "$GRADLE_TASK"
- gradlew_path: "$GRADLEW_PATH"
- apk_file_include_filter: $APK_FILE_INCLUDE_FILTER

test:
steps:
- path::./:
is_skippable: true
title: Step Test - keystore pass == key pass
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_1_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_1
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_1
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_1
- path::./:
is_skippable: true
title: Step Test - keystore pass != key pass
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_2_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_2
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_2
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_2
- path::./:
is_skippable: true
title: Step Test - default alias
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_3_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_3
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_3
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_3
- path::./:
is_skippable: true
title: Step Test - android studio generated keystore (jks)
inputs:
- keystore_url: $BITRISEIO_ANDROID_KEYSTORE_4_URL
- keystore_password: $BITRISEIO_ANDROID_KEYSTORE_PASSWORD_4
- keystore_alias: $BITRISEIO_ANDROID_KEYSTORE_ALIAS_4
- private_key_password: $BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD_4

_go_tests:
steps:
Expand Down
20 changes: 10 additions & 10 deletions keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewHelper(keystorePth, keystorePassword, alias string) (Helper, error) {
}, nil
}

func (helper Helper) createSignCmd(apkPth, destApkPth, privateKeyPassword string) ([]string, error) {
func (helper Helper) createSignCmd(buildArtifactPth, destBuildArtifactPth, privateKeyPassword string) ([]string, error) {
split := strings.Split(helper.signatureAlgorithm, "with")
if len(split) != 2 {
return []string{}, fmt.Errorf("failed to parse signature algorithm: %s", helper.signatureAlgorithm)
Expand Down Expand Up @@ -139,20 +139,20 @@ func (helper Helper) createSignCmd(apkPth, destApkPth, privateKeyPassword string
cmdSlice = append(cmdSlice, "-keypass", privateKeyPassword)
}

cmdSlice = append(cmdSlice, "-signedjar", destApkPth, apkPth, helper.alias)
cmdSlice = append(cmdSlice, "-signedjar", destBuildArtifactPth, buildArtifactPth, helper.alias)

return cmdSlice, nil
}

// SignAPK ...
func (helper Helper) SignAPK(apkPth, destApkPth, privateKeyPassword string) error {
if exist, err := pathutil.IsPathExists(apkPth); err != nil {
// SignBuildArtifact ...
func (helper Helper) SignBuildArtifact(buildArtifactPth, destBuildArtifactPth, privateKeyPassword string) error {
if exist, err := pathutil.IsPathExists(buildArtifactPth); err != nil {
return err
} else if !exist {
return fmt.Errorf("APK not exist at: %s", apkPth)
return fmt.Errorf("Build Artifact not exist at: %s", buildArtifactPth)
}

cmdSlice, err := helper.createSignCmd(apkPth, destApkPth, privateKeyPassword)
cmdSlice, err := helper.createSignCmd(buildArtifactPth, destBuildArtifactPth, privateKeyPassword)
if err != nil {
return err
}
Expand All @@ -170,14 +170,14 @@ func (helper Helper) SignAPK(apkPth, destApkPth, privateKeyPassword string) erro
return nil
}

// VerifyAPK ...
func (helper Helper) VerifyAPK(apkPth string) error {
// VerifyBuildArtifact ...
func (helper Helper) VerifyBuildArtifact(buildArtifactPth string) error {
cmdSlice := []string{
jarsigner,
"-verify",
"-verbose",
"-certs",
apkPth,
buildArtifactPth,
}

prinatableCmd := command.PrintableCommandArgs(false, cmdSlice)
Expand Down
Loading

0 comments on commit 80363a9

Please sign in to comment.