Integrate uninstalling previous versions into AAR release script.

This allows the script to be reliably run on the bots.

Bug: webrtc:8365
Change-Id: Ie4f216403c1f4fabe8db07f261fe06d1e64be0ae
Reviewed-on: https://webrtc-review.googlesource.com/42720
Reviewed-by: Edward Lemur <ehmaldonado@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21717}
diff --git a/tools_webrtc/android/release_aar.py b/tools_webrtc/android/release_aar.py
index c2ae065..1e91bf9 100644
--- a/tools_webrtc/android/release_aar.py
+++ b/tools_webrtc/android/release_aar.py
@@ -52,6 +52,8 @@
 UPLOAD_RETRY_BASE_SLEEP_SECONDS = 2.0
 GRADLEW_BIN = os.path.join(CHECKOUT_ROOT,
                            'examples/androidtests/third_party/gradle/gradlew')
+ADB_BIN = os.path.join(CHECKOUT_ROOT,
+                       'third_party/android_tools/sdk/platform-tools/adb')
 AAR_PROJECT_DIR = os.path.join(CHECKOUT_ROOT, 'examples/aarproject')
 AAR_PROJECT_GRADLE = os.path.join(AAR_PROJECT_DIR, 'build.gradle')
 AAR_PROJECT_APP_GRADLE = os.path.join(AAR_PROJECT_DIR, 'app', 'build.gradle')
@@ -168,6 +170,12 @@
     with open(AAR_PROJECT_APP_GRADLE, 'w') as gradle_app_file:
       gradle_app_file.write(gradle_app)
 
+    # Uninstall any existing version of AppRTCMobile.
+    logging.info('Uninstalling previous AppRTCMobile versions. It is okay for '
+                 'these commands to fail if AppRTCMobile is not installed.')
+    subprocess.call([ADB_BIN, 'uninstall', 'org.appspot.apprtc'])
+    subprocess.call([ADB_BIN, 'uninstall', 'org.appspot.apprtc.test'])
+
     # Run tests.
     try:
       # First clean the project.