Malcolm Crum
Malcolm Crum

Reputation: 4869

Version UIAutomator test package

I have a UIAutomator test that interacts with the OS to automate some tasks that I can't do from ADB or another app. Sometimes I release a new version of the tests. I planned on using adb shell dumpsys package my.package.test | grep versionName to parse the version from the test app, and update it if necessary.

However, it appears that dumpsys package returns versionName=null for my UIAutomator test (built using a gradle script near-identical to the sample).

Right now I'm just overwriting the test every time I need it. Is there some way to embed version information in a UIAutomator test APK?

Upvotes: 0

Views: 331

Answers (1)

Diego Torres Milano
Diego Torres Milano

Reputation: 69188

There's no version information in the default manifest generated for the test APK, then you have to introduce it.

1.

add this to your build.gradle:

defaultConfig {
        manifestPlaceholders = [ versionName:versionName, versionCode:versionCode]
}

2.

copy your main AndroidManifest.xml to src/androidTest

3.

edit the test manifest

<!--suppress AndroidDomInspection -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="your.package.name"
    android:versionCode="${versionCode}"
    android:versionName="${versionName}"
    >
    <application
        tools:node="remove"
        ... >
    </application>
</manifest>

4.

Once rebuilt, your test APK will include version information.

Upvotes: 1

Related Questions