Skip to content

Commit

Permalink
Fix app APK export when building library module (#21)
Browse files Browse the repository at this point in the history
* Fix app APK export when building library module

* Update go-android, fix YAML lint issue

* Disable install-missing-android-tools step in tests

* Re-add JDK 11 step to E2E tests

* Revert to custom script

* Permanently remove install-missing-android-tools step

* Use master branch

* Use correct variant for master branch

* Use updated sample app

* Restore install-missing-android-tools
  • Loading branch information
ofalvai authored Nov 22, 2021
1 parent 0541428 commit 88443b3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris
| Key | Description | Flags | Default |
| --- | --- | --- | --- |
| `project_location` | The root directory of your android project, for example, where your root build gradle file exist (also gradlew, settings.gradle, etc...) | required | `$BITRISE_SOURCE_DIR` |
| `module` | Set the module that you want to build. To see your available modules please open your project in Android Studio and go in [Project Structure] and see the list on the left. | required | |
| `module` | Set the module to build. Valid syntax examples: `app`, `feature:nested-module` To see your available modules please open your project in Android Studio and go in [Project Structure] and see the list on the left. | required | |
| `variant` | Set the variant that you want to build. To see your available variants please open your project in Android Studio and go in [Project Structure] -> variants section. | required | |
| `apk_path_pattern` | Will find the APK files with the given pattern. | required | `*/build/outputs/apk/*.apk` |
| `cache_level` | `all` - will cache build cache and dependencies `only_deps` - will cache dependencies only `none` - will not cache anything | required | `only_deps` |
Expand Down
2 changes: 1 addition & 1 deletion bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

workflows:
generate-readme:
generate_readme:
steps:
- git::https://github.com/bitrise-steplib/steps-readme-generator.git@main: { }

Expand Down
19 changes: 9 additions & 10 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

app:
envs:
# Shared test configs
- TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git
- TEST_APP_BRANCH: maintenance

workflows:
test_app:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git
- TEST_APP_BRANCH: maintenance
- TEST_APP_MODULE: app
- TEST_APP_VARIANT: DemoDebug
after_run:
- _run
- _check_outputs

test_another_app:
test_library_module:
envs:
- TEST_APP_MODULE: another_app
- TEST_APP_VARIANT: AnotherDemoDebug
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-Android-Modules-Sample.git
- TEST_APP_BRANCH: main
- TEST_APP_MODULE: feature:example1
- TEST_APP_VARIANT: debug
- GRADLE_ARGUMENTS: :app:assembleDebug # workaround for building a main app for a library module
after_run:
- _run
- _check_outputs
Expand Down Expand Up @@ -62,7 +61,7 @@ workflows:
- project_location: ./_tmp
- module: $TEST_APP_MODULE
- variant: $TEST_APP_VARIANT
- arguments: --warn
- arguments: $GRADLE_ARGUMENTS --warn

_check_outputs:
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing
go 1.16

require (
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6
github.com/bitrise-io/go-android v0.0.0-20211122121320-da1559f13057
github.com/bitrise-io/go-steputils v0.0.0-20210819160244-b3962254d553
github.com/bitrise-io/go-utils v0.0.0-20210819143908-bbd923881fab
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e h1:lkJnz+yXb
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e/go.mod h1:gGXmY8hJ1x44AC98TIvZZvxP7o+hs4VI6wgmO4JMfEg=
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6 h1:WJQ7dvHP7/ZtS9qw/Ng+/eh+5MPOVVKDrjjrDNiWlwA=
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc=
github.com/bitrise-io/go-android v0.0.0-20211122110116-3cea9a1433e0 h1:NC+cXb5vxirX66GskpR1z4oW1iALjcT7T9qvDHr8TOc=
github.com/bitrise-io/go-android v0.0.0-20211122110116-3cea9a1433e0/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc=
github.com/bitrise-io/go-android v0.0.0-20211122121320-da1559f13057 h1:KZi5Lg2g3Mv8x71pquul/UbEZfugFCF0k/kv3oi5IH4=
github.com/bitrise-io/go-android v0.0.0-20211122121320-da1559f13057/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1 h1:gi29hTdxGXAGQvZckPZ9V8BAEfP3eK/tiZgTC5s6h1c=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
Expand Down
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func androidTestVariantPairs(module string, variantsMap gradle.Variants) (gradle
}

func mainE(config Configs) error {
started := time.Now()

gradleProject, err := gradle.NewProject(config.ProjectLocation, cmdFactory)
if err != nil {
return fmt.Errorf("Failed to open project, error: %s", err)
Expand All @@ -152,6 +154,8 @@ func mainE(config Configs) error {
}

logger.Infof("Variants:")
logger.Printf("Reading Gradle project structure, this might take a while...")
logger.Println()

variants, err := buildTask.GetVariants(args...)
if err != nil {
Expand Down Expand Up @@ -190,8 +194,6 @@ func mainE(config Configs) error {
fmt.Println()
}

started := time.Now()

logger.Infof("Run build:")
buildCommand := buildTask.GetCommand(filteredVariants, args...)

Expand All @@ -204,14 +206,20 @@ func mainE(config Configs) error {

fmt.Println()

logger.Infof("Export APKs:")
fmt.Println()

logger.Infof("APKs found after the build:")
apks, err := getArtifacts(gradleProject, started, config.APKPathPattern, false)
if err != nil {
return fmt.Errorf("failed to find apks, error: %v", err)
return fmt.Errorf("failed to find APKs: %v", err)
}

for i, apk := range apks {
logger.Printf("%d. %s", i+1, apk.Path)
}

fmt.Println()
logger.Infof("Export APKs:")
fmt.Println()

exportedArtifactPaths, err := exportArtifacts(apks, config.DeployDir)
if err != nil {
return fmt.Errorf("Failed to export artifact: %v", err)
Expand All @@ -220,7 +228,7 @@ func mainE(config Configs) error {
var exportedAppArtifact string
var exportedTestArtifact string
for _, pth := range exportedArtifactPaths {
if strings.HasSuffix(strings.ToLower(path.Base(pth)), strings.ToLower("AndroidTest.apk")) {
if strings.HasSuffix(strings.ToLower(path.Base(pth)), "androidtest.apk") {
exportedTestArtifact = pth
} else {
exportedAppArtifact = pth
Expand Down Expand Up @@ -251,7 +259,6 @@ func mainE(config Configs) error {
paths += sep + "$BITRISE_DEPLOY_DIR/" + filepath.Base(path)
sep = "| \\\n" + strings.Repeat(" ", 11)
}
fmt.Println()

return nil
}
Expand Down
7 changes: 5 additions & 2 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ inputs:
- module: ""
opts:
title: Module
summary: |
Set the module that you want to build. To see your available modules please open your project in Android Studio and go in [Project Structure] and see the list on the left.
summary: "Set the module to build. Valid syntax examples: `app`, `feature:nested-module`"
description: |
Set the module to build. Valid syntax examples: `app`, `feature:nested-module`
To see your available modules please open your project in Android Studio and go in [Project Structure] and see the list on the left.
is_required: true
- variant: ""
opts:
Expand Down
7 changes: 6 additions & 1 deletion vendor/github.com/bitrise-io/go-android/gradle/project.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6
# github.com/bitrise-io/go-android v0.0.0-20211122121320-da1559f13057
## explicit
github.com/bitrise-io/go-android/cache
github.com/bitrise-io/go-android/gradle
Expand Down

0 comments on commit 88443b3

Please sign in to comment.