1

I use ./gradlew assembleAndroidTest to create app-debug-androidTest.apk, but the versionCode for apk is always 0. Is there any to set the versionCode for app-debug-androidTest.apk.

Thanks!

For normal apk, I can set in AndroidManifest.xml:

android:versionCode="110"
android:versionName="3.0.17 alpha"

or in build.gralde:

defaultConfig {
    applicationId "com.android.searchui"
    minSdkVersion 18
    targetSdkVersion 22
    versionCode 84
    versionName "9.4"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

But when during instrumented tests, there are generated two .apk files. And the smaller one is app-debug-androidTest-unaligned.apk and it's versionCode is 0.

Updated on 2017/8/4:

I think it's very difficult to do this because the com.android.application gradle plugin didn't provider androidTest apk versionCode setting.

So I just put a version.xml to src/androidTest/res/values folder:

<resources>
    <integer name="versionCode">111</integer>
</resources>

Use this to fake versionCode.

user3875388
  • 541
  • 1
  • 6
  • 19

4 Answers4

1

you can copy the src/main/AndroidManifest.xml to src/androidTest/AndroidManifest.xml

then add android:versionCode and android:versionName in src/androidTest/AndroidManifest.xml

chao.xie
  • 11
  • 2
0

Just add this to your manifest

 android:versionCode="110"
 android:versionName="3.0.17 alpha"

you can set your desired version code and name

Nivil Boban
  • 286
  • 1
  • 13
  • For normal apk, this works, but for androidTest apk. [It has be ignored](https://stackoverflow.com/questions/26244998/androidmanifest-in-androidtest-directory-being-ignored) – user3875388 Aug 03 '17 at 11:05
0

Go to /app/build.gradle.
There you can give versionCode and versionName For eg

defaultConfig {
    applicationId "your package name"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 2
    versionName "1.0.1"

}
Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
0
  1. dump test apk java -jar ~/apktool_2.4.0.jar d ./app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk

  2. copy AndroidManifest.xml to androidTest cp app-debug-androidTest/AndroidManifest.xml app/src/androidTest/

  3. add android:versionCode and android:versionName in AndroidManifest.xml

  4. rebuild test apk

K.J. Kao
  • 1
  • 2