# Extract APK Info for multiple flavors

**URL:** <https://discuss.bitrise.io/t/extract-apk-info-for-multiple-flavors/1246>\
**Category:** Question & Answer\
**Tags:** step, android\
**Created:** [March 23, 2017, 12:22pm UTC](https://discuss.bitrise.io/t/extract-apk-info-for-multiple-flavors/1246 "2017-03-23T12:22:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raphaelmina](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/raphaelmina/32/419_2.png) [@raphaelmina](https://discuss.bitrise.io/u/raphaelmina)\
**Post date:** [March 23, 2017, 12:22pm UTC](https://discuss.bitrise.io/t/extract-apk-info-for-multiple-flavors/1246/1 "2017-03-23T12:22:29Z")

</div>

Hello,

I have an Android project with multiple flavors. In my current workflow, the step “Deploy to Bitrise” generates one public URL per flavor, so I get as many APK as there are flavors.

I want to send the details of all generated APKs to an external webservice, using a script. I’ve added a step “APK Info” which creates the variables $ANDROID\_APP\_PACKAGE\_NAME, $ANDROID\_APP\_VERSION\_NAME, etc. Then I run a script which works fine, but only for one APK (I guess the lastly generated APK).

To solve that, my idea would be to run one “Apk info” step per flavor, but my Gradle Runner step only generates one $BITRISE\_APK\_PATH. Is that a good approach ? If yes, how can I modify the Gradle Runner step to generate multiple environnement variable (one for each flavor).

Thanks in advance for your feedback.

---

<div class="post-metadata">

**Author:** ![tamaspapik](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/tamaspapik/32/251_2.png) [@tamaspapik](https://discuss.bitrise.io/u/tamaspapik)\
**Post date:** [March 27, 2017, 8:22am UTC](https://discuss.bitrise.io/t/extract-apk-info-for-multiple-flavors/1246/2 "2017-03-27T08:22:49Z")

</div>

Hey @raphaelmina! 👋🏻

@godreikrisztian:

> So all of your apks are moved to BITRISE\_DEPLOY\_DIR but only the last one is exported into BITRISE\_APK\_PATH env.

> Every step after the gradle-runner uses BITRISE\_APK\_PATH (so the last apk)

- 

> i think the easy solution would be to:

> search every file with .apk extension in BITRISE\_DEPLOY\_DIR  
> then loop over this apks, collect the desired infos and upload per apk

You can do this with a script step:

```auto
package_name_regex="package: name='(.+)' versionCode='(.+)' versionName='(.+)' "
app_name_regex="application: label='(.+)' icon='(.+)'"

find_apks_output="$(find $BITRISE_DEPLOY_DIR -name *release.apk)"
while IFS= read -r apk
do
    apk_size=$(wc -c <"$apk")

    infos="$($ANDROID_HOME/build-tools/25.0.2/aapt dump badging $apk)"
    while read -r line 
    do
        # echo "... $line ..."
        if [[$line =~ $package_name_regex]]
        then
            package_name="${BASH_REMATCH[1]}"
            

            version_code="${BASH_REMATCH[2]}"
            

            version_name="${BASH_REMATCH[3]}"
        elif [[$line =~ $app_name_regex]]
        then
            app_name="${BASH_REMATCH[1]}"

            icon_path="${BASH_REMATCH[2]}"
            
        fi
    done <<< "$infos"

    echo "BITRISE_APK_PATH: $apk"
    echo "ANDROID_APP_PACKAGE_NAME: $package_name"
    echo "ANDROID_APK_FILE_SIZE: $apk_size bytes"
    echo "ANDROID_APP_NAME: $app_name"
    echo "ANDROID_APP_VERSION_NAME: $version_name"
    echo "ANDROID_APP_VERSION_CODE: $version_code"
    echo "ANDROID_ICON_PATH: $icon_path"
    echo "BITRISE_PUBLIC_INSTALL_PAGE_URL: $BITRISE_PUBLIC_INSTALL_PAGE_URL"

    echo
done <<< "${find_apks_output}"

```

Please take care when you run the script, the following path can be different, please change the version accordingly:

```auto
 infos="$($ANDROID_HOME/build-tools/>25.0.2</aapt dump badging $apk)"

```

Thank you for reporting this @raphaelmina!  
🎉🚀

---

<div class="post-metadata">

**Author:** ![raphaelmina](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/raphaelmina/32/419_2.png) [@raphaelmina](https://discuss.bitrise.io/u/raphaelmina)\
**Post date:** [March 27, 2017, 8:28am UTC](https://discuss.bitrise.io/t/extract-apk-info-for-multiple-flavors/1246/3 "2017-03-27T08:28:27Z")

</div>

Thanks for this complete solution, it works perfect.
