App is uninstalled after playing instrumented tests since migration to Giraffe

578 Views Asked by At

I have used Flamingo for some time, and after playing an Espresso test, the app was still installed.

Then I upgraded to Giraffe, and now, after playing an Espresso test, the app is uninstalled. I did not changed my project, just upgraded Android studio. Any idea of what can be done so that the app is not uninstalled in this case?

Note: after running the app itself, it is not uninstalled.

4

There are 4 best solutions below

0
kotlin_aj On BEST ANSWER

The issue tracker says:

"Added android.injected.androidTest.leaveApksInstalledAfterRun field in gradle.properties. Setting this field to false indicates that in the current project, all the APKs installed during test will be uninstalled after test finishes. Setting it to true means that AGP will leave the test APKs untouched after test. Default is false"

"This will be available starting in AGP 8.3.0-alpha07"

"The fixes for this issue are now also available in:

Android Studio Hedgehog | 2023.1.1 RC 1 Android Gradle Plugin 8.2.0-rc01"

Confirmed upgrading to Android Studio Hedgehog, upgrading to Gradle 8.2 and adding the following to my gradle.properties file resulted in the app remaining on the emulator after running tests.

android.injected.androidTest.leaveApksInstalledAfterRun=true

1
Laurent D. On

After more tests and searches, I finally found that the change is in the Android Gradle Plugin.

  • Version 7.4.2 : apks are not removed
  • version 8.1: apks are removed

there is an issu tracker : https://issuetracker.google.com/issues/295039976

1
Sergii On

Steps:

  1. In app level gradle.properties file update property androidGradlePluginVersion=8.2.0
  2. In root gradle.properties file add property android.injected.androidTest.leaveApksInstalledAfterRun=true
  3. In gradle-wrapper.properties update property distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
  4. Update Android Studio to Hedgehog | 2023.1.1 release. Just click Help > Check for updates on Windows or Android Studio > Check for updates on macOS and it is there.
0
CoolMind On
  1. Tools > AGP Upgrade Assistant...

  2. Select 8.2.2 and press Run selected steps.

It will set classpath("com.android.tools.build:gradle:8.2.2") and implementation("com.android.tools.build:gradle:8.2.2"). In my case it showed errors during synchronization of project with gradle files. You should fix them if any.

  1. You can upgrade Gradle in gradle-wrapper.properties: distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip.

  2. Don't apply an advice from https://developer.android.com/build/releases/gradle-plugin#updating-plugin: id("com.android.application") version "8.2.2" apply false, it will show an error that can't be fixed.

  3. Insert in gradle.properties: android.injected.androidTest.leaveApksInstalledAfterRun=true.

I already have Android Studio Hedgehog | 2023.1.1 Patch 2 release. Of course, you should press Sync Project with Gradle Files.