Skip to content

Commit

Permalink
Remove Universal APK generation (#142)
Browse files Browse the repository at this point in the history
* Add .idea to .gitignore

* Remove inputs related to generating Universal APKs from step.yml

* Remove Universal APK generation logic

* Fix typo

* Removed unused method
  • Loading branch information
Bence1001 authored Sep 10, 2021
1 parent 26f92e4 commit 27edc12
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ _tmp
.bundle/
# built executable
steps-deploy-to-bitrise-io
/.idea/
100 changes: 0 additions & 100 deletions aabutil.go

This file was deleted.

25 changes: 2 additions & 23 deletions androidartifact/file_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func mapBuildArtifacts(pths []string) ArtifactMap {

if filepath.Ext(pth) == ".aab" {
if len(artifact.AAB) != 0 {
log.Warnf("Multple AAB generated for module: %s, productFlavour: %s, buildType: %s: %s", info.Module, info.ProductFlavour, info.BuildType, pth)
log.Warnf("Multiple AAB generated for module: %s, productFlavour: %s, buildType: %s: %s", info.Module, info.ProductFlavour, info.BuildType, pth)
}
artifact.AAB = pth
buildTypeArtifacts[info.ProductFlavour] = artifact
Expand All @@ -214,7 +214,7 @@ func mapBuildArtifacts(pths []string) ArtifactMap {

if info.SplitInfo.Universal {
if len(artifact.UniversalApk) != 0 {
log.Warnf("Multple universal APK generated for module: %s, productFlavour: %s, buildType: %s: %s", info.Module, info.ProductFlavour, info.BuildType, pth)
log.Warnf("Multiple universal APK generated for module: %s, productFlavour: %s, buildType: %s: %s", info.Module, info.ProductFlavour, info.BuildType, pth)
}
artifact.UniversalApk = pth
}
Expand Down Expand Up @@ -266,24 +266,3 @@ func CreateSplitArtifactMeta(pth string, pths []string) (SplitArtifactMeta, erro

return SplitArtifactMeta(artifact), nil
}

// UniversalAPKBase returns the aab's universal apk pair's base name.
func UniversalAPKBase(basedOnAAB string) string {
// <module>-<product_flavor>?-universal-<build type>-<unsigned|bitrise-signed>?.apk
info := ParseArtifactPath(basedOnAAB)

nameParts := []string{info.Module}
if len(info.ProductFlavour) > 0 {
nameParts = append(nameParts, info.ProductFlavour)
}
nameParts = append(nameParts, "universal", info.BuildType)

name := strings.Join(nameParts, "-")
if info.SigningInfo.Unsigned {
name = name + unsignedSuffix
} else if info.SigningInfo.BitriseSigned {
name = name + bitriseSignedSuffix
}
name += ".apk"
return name
}
31 changes: 0 additions & 31 deletions androidartifact/file_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,37 +425,6 @@ func TestCreateSplitArtifactMeta(t *testing.T) {
}
}

func TestUniversalAPKBase(t *testing.T) {
tests := []struct {
name string
basedOnAAB string
want string
}{
{
name: "simple test",
basedOnAAB: "app-release.aab",
want: "app-universal-release.apk",
},
{
name: "bitrise signed aab",
basedOnAAB: "app-release-bitrise-signed.aab",
want: "app-universal-release-bitrise-signed.apk",
},
{
name: "2 flavours",
basedOnAAB: "app-minApi21-demo-debug.aab",
want: "app-minApi21-demo-universal-debug.apk",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := UniversalAPKBase(tt.basedOnAAB); got != tt.want {
t.Errorf("UniversalAPKBase() = %v, want %v", got, tt.want)
}
})
}
}

func TestFindSameArtifact(t *testing.T) {
type args struct {
pth string
Expand Down
49 changes: 0 additions & 49 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"

"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/androidartifact"
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test"

"github.com/bitrise-io/envman/envman"
Expand Down Expand Up @@ -39,7 +38,6 @@ type Config struct {
AppSlug string `env:"BITRISE_APP_SLUG,required"`
AddonAPIBaseURL string `env:"addon_api_base_url,required"`
AddonAPIToken string `env:"addon_api_token"`
GenerateUniversalApkIfNone bool `env:"generate_universal_apk_if_none,opt[true,false]"`
DebugMode bool `env:"debug_mode,opt[true,false]"`
BundletoolVersion string `env:"bundletool_version,required"`
}
Expand Down Expand Up @@ -286,38 +284,6 @@ func deployTestResults(config Config) {
}
}

func findUniversalAPKPair(aab string, apks []string) string {
universalAPKBase := androidartifact.UniversalAPKBase(aab)
return androidartifact.FindSameArtifact(universalAPKBase, apks)
}

func ensureAABsHasUniversalAPKPair(aabs, apks []string, bundletoolVersion string) ([]string, map[string]string, error) {
aabAPKPairs := map[string]string{}
for _, aab := range aabs {
log.Debugf("Looking for universal APK pair for: %s", aab)

universalAPKPair := findUniversalAPKPair(aab, apks)
if len(universalAPKPair) == 0 {
log.Debugf("Does not have universal APK pair, generating...")

var err error
universalAPKPair, err = GenerateUniversalAPK(aab, bundletoolVersion)
if err != nil {
return nil, nil, err
}

log.Debugf("Generated universal APK pair: %s", universalAPKPair)

apks = append(apks, universalAPKPair)
} else {
log.Debugf("Universal APK pair: %s", universalAPKPair)
}

aabAPKPairs[aab] = universalAPKPair
}
return apks, aabAPKPairs, nil
}

func findAPKsAndAABs(pths []string) (apks []string, aabs []string, others []string) {
for _, pth := range pths {
switch getFileType(pth) {
Expand All @@ -335,23 +301,8 @@ func findAPKsAndAABs(pths []string) (apks []string, aabs []string, others []stri
func deploy(clearedFilesToDeploy []string, config Config) (ArtifactURLCollection, error) {
apks, aabs, others := findAPKsAndAABs(clearedFilesToDeploy)

log.Warnf(`Universal APK generation is going to be DEPRECATED with the next major release! In case you build a bundle and you would like to
export a universal APK to distribute it for testing (by Public install page or Ship Add-on), please use the Export Universal APK Step instead!
You may find further information about the Step here (https://devcenter.bitrise.io/deploy/android-deploy/exporting-a-universal-apk-from-an-aab/).`)

if config.GenerateUniversalApkIfNone {
var err error
apks, _, err = ensureAABsHasUniversalAPKPair(aabs, apks, config.BundletoolVersion)
if err != nil {
return ArtifactURLCollection{}, err
}
} else {
log.Printf("Does not have universal APK pair but ignoring generation.")
}

androidArtifacts := append(apks, aabs...)

// deploy the apks first, as the universal apk's public install page will be used for aabs.
artifactURLCollection := ArtifactURLCollection{
PublicInstallPageURLs: map[string]string{},
PermanentDownloadURLs: map[string]string{},
Expand Down
35 changes: 0 additions & 35 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,6 @@ import (
"testing"
)

func Test_findUniversalAPKPair(t *testing.T) {
tests := []struct {
name string
aab string
apks []string
want string
}{
{
name: "Only universal apk can be the pair",
aab: "app-minApi21-demo-debug-bitrise-signed.aab",
apks: []string{"app-minApi21-demo-debug.apk"},
want: "",
},
{
name: "Finds if aab is bitrise-signed",
aab: "app-minApi21-demo-debug-bitrise-signed.aab",
apks: []string{"app-minApi21-demo-universal-debug.apk"},
want: "app-minApi21-demo-universal-debug.apk",
},
{
name: "Finds if aab is bitrise-signed, even if apk is unsigned",
aab: "app-minApi21-demo-debug-bitrise-signed.aab",
apks: []string{"app-minApi21-demo-universal-debug-unsigned.apk"},
want: "app-minApi21-demo-universal-debug-unsigned.apk",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findUniversalAPKPair(tt.aab, tt.apks); got != tt.want {
t.Errorf("findUniversalAPKPair() = %v, want %v", got, tt.want)
}
})
}
}

func Test_generateUrlOutputWithTemplate(t *testing.T) {
defaultTemplate := "{{range $index, $element := .}}{{if $index}}|{{end}}{{$element.File}}=>{{$element.URL}}{{end}}"
temp := template.New("test")
Expand Down
16 changes: 2 additions & 14 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,6 @@ inputs:
The token required to authenticate with the API.
is_dont_change_value: true
is_sensitive: true
- generate_universal_apk_if_none: "true"
opts:
title: "Force generate universal APK for AABs (DEPRECATED)"
description: |
Universal APK generation is scheduled to be **DEPRECATED** in the next
major release. Please use the **Export Universal APK** Step instead! You
may find further information about the Step in our [Exporting a universal APK from an AAB](https://devcenter.bitrise.io/deploy/android-deploy/exporting-a-universal-apk-from-an-aab/) article.
When building an AAB artifact, check for a corresponding universal APK.
If none is found, generate the corresponding locally (debug) signed
universal APK for easier debugging.
- debug_mode: "false"
opts:
category: Debug
Expand All @@ -245,14 +234,13 @@ inputs:
- "false"
- "true"
- bundletool_version: "0.13.4"
opts:
opts:
category: Debug
title: "Bundletool version"
summary: The specific bundletool version you want to use.
description: |-
If you need a specific [bundletool version]((https://github.com/google/bundletool/releases) other than the default version,
you can modify the value of the **Bundletool version** required input.
Bundletool generates an APK from an Android App Bundle so that you can test the APK.
you can modify the value of the **Bundletool version** required input.
is_required: true
outputs:
- BITRISE_PUBLIC_INSTALL_PAGE_URL:
Expand Down

0 comments on commit 27edc12

Please sign in to comment.