Android APK tests built from a normal WebRTC checkout.

Restructure how the Android APK tests are compiled now
that we have a Chromium checkout available (since r6938).

This removes the need of several hacks that were needed when
building these targets from inside a Chromium checkout.
By creating a symlink to Chromium's base we can compile the required
targets. This also removes the need of the previously precompiled
binaries we keep in /deps/tools/android at Google code.

All the user needs to do is to add the target_os = ["android"]
entry to his .gclient as described at
https://code.google.com/p/chromium/wiki/AndroidBuildInstructions

Before committing this CL, the Android APK buildbots will need
to be updated.
This also solves http://crbug.com/402594 since the apply_svn_patch.py
usage will be similar to the other standalone bots.
It also solves http://crbug.com/399297

BUG=chromium:399297, chromium:402594
TESTED=Locally compiled all APK targets by running:
GYP_DEFINES="OS=android include_tests=1 enable_tracing=1" gclient runhooks
ninja -C out/Release

checkdeps

R=henrike@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/22149004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7014 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/.gitignore b/.gitignore
index 2535251..f1490c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@
 .settings
 .sw?
 /Makefile
+/base
 /build
 /buildtools
 /chromium/.gclient.bot
@@ -94,8 +95,8 @@
 /third_party/valgrind
 /third_party/winsdk_samples/src
 /third_party/yasm
+/third_party/zlib
 /tools/android
-/tools/android-dummy-test
 /tools/clang
 /tools/find_depot_tools.py
 /tools/generate_library_loader
diff --git a/DEPS b/DEPS
index ee73527..99b1aa3 100644
--- a/DEPS
+++ b/DEPS
@@ -34,15 +34,14 @@
     "third_party/winsdk_samples/src":
       (Var("googlecode_url") % "webrtc") + "/deps/third_party/winsdk_samples_v71@3145",
   },
-
-  "android": {
-    # Precompiled tools needed for Android test execution. Needed since we can't
-    # compile them from source in WebRTC since they depend on Chromium's base.
-    "tools/android":
-      (Var("googlecode_url") % "webrtc") + "/deps/tools/android@6306",
-  },
 }
 
+include_rules = [
+  # Base is only used to build Android APK tests and may not be referenced by
+  # WebRTC production code.
+  "-base",
+]
+
 hooks = [
   {
     # Clone chromium and its deps.
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 430628c..d5d2344 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -7,6 +7,7 @@
 # be found in the AUTHORS file in the root of the source tree.
 
 import re
+import sys
 
 
 def _CheckNoIOStreamInHeaders(input_api, output_api):
@@ -112,6 +113,60 @@
         items=gyp_files))
   return result
 
+def _CheckUnwantedDependencies(input_api, output_api):
+  """Runs checkdeps on #include statements added in this
+  change. Breaking - rules is an error, breaking ! rules is a
+  warning.
+  """
+  # Copied from Chromium's src/PRESUBMIT.py.
+
+  # We need to wait until we have an input_api object and use this
+  # roundabout construct to import checkdeps because this file is
+  # eval-ed and thus doesn't have __file__.
+  original_sys_path = sys.path
+  try:
+    sys.path = sys.path + [input_api.os_path.join(
+        input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
+    import checkdeps
+    from cpp_checker import CppChecker
+    from rules import Rule
+  finally:
+    # Restore sys.path to what it was before.
+    sys.path = original_sys_path
+
+  added_includes = []
+  for f in input_api.AffectedFiles():
+    if not CppChecker.IsCppFile(f.LocalPath()):
+      continue
+
+    changed_lines = [line for _line_num, line in f.ChangedContents()]
+    added_includes.append([f.LocalPath(), changed_lines])
+
+  deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
+
+  error_descriptions = []
+  warning_descriptions = []
+  for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
+      added_includes):
+    description_with_path = '%s\n    %s' % (path, rule_description)
+    if rule_type == Rule.DISALLOW:
+      error_descriptions.append(description_with_path)
+    else:
+      warning_descriptions.append(description_with_path)
+
+  results = []
+  if error_descriptions:
+    results.append(output_api.PresubmitError(
+        'You added one or more #includes that violate checkdeps rules.',
+        error_descriptions))
+  if warning_descriptions:
+    results.append(output_api.PresubmitPromptOrNotify(
+        'You added one or more #includes of files that are temporarily\n'
+        'allowed but being removed. Can you avoid introducing the\n'
+        '#include? See relevant DEPS file(s) for details and contacts.',
+        warning_descriptions))
+  return results
+
 
 def _CommonChecks(input_api, output_api):
   """Checks common to both upload and commit."""
@@ -160,6 +215,7 @@
   results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
   results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
   results.extend(_CheckGypChanges(input_api, output_api))
+  results.extend(_CheckUnwantedDependencies(input_api, output_api))
   return results
 
 
diff --git a/setup_links.py b/setup_links.py
index 81da2f7..bb4b111 100755
--- a/setup_links.py
+++ b/setup_links.py
@@ -37,8 +37,6 @@
   'google_apis',  # Needed by build/common.gypi.
   'net',
   'testing',
-  'third_party/android_testrunner',
-  'third_party/android_tools',
   'third_party/binutils',
   'third_party/boringssl',
   'third_party/colorama',
@@ -62,6 +60,7 @@
   'third_party/syzygy',
   'third_party/usrsctp',
   'third_party/yasm',
+  'third_party/zlib',
   'tools/clang',
   'tools/generate_library_loader',
   'tools/gn',
@@ -74,6 +73,15 @@
   'tools/win',
 ]
 
+from sync_chromium import get_target_os_list
+if 'android' in get_target_os_list():
+  DIRECTORIES += [
+    'base',
+    'third_party/android_testrunner',
+    'third_party/android_tools',
+    'tools/android',
+  ]
+
 FILES = {
   '.gn': None,
   'tools/find_depot_tools.py': None,
diff --git a/webrtc/build/apk_tests.gyp b/webrtc/build/apk_tests.gyp
deleted file mode 100644
index 0185975..0000000
--- a/webrtc/build/apk_tests.gyp
+++ /dev/null
@@ -1,235 +0,0 @@
-# Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
-#
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file in the root of the source
-# tree. An additional intellectual property rights grant can be found
-# in the file PATENTS.  All contributing project authors may
-# be found in the AUTHORS file in the root of the source tree.
-
-# This file exists in two versions. A no-op version under
-# webrtc/build/apk_tests_noop.gyp and this one. This gyp file builds the apk
-# unit tests (for Android) assuming that WebRTC is built inside a Chromium
-# workspace. The no-op version is included when building WebRTC without
-# Chromium. This is a workaround for the fact that 'includes' don't expand
-# variables and that the relative location of apk_test.gypi is different for
-# WebRTC when built as part of Chromium and when it is built without Chromium.
-{
-  'includes': [
-    'common.gypi',
-  ],
-  'targets': [
-    {
-      'target_name': 'audio_decoder_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'audio_decoder_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)audio_decoder_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/modules/modules.gyp:audio_decoder_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'common_audio_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'common_audio_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)common_audio_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/common_audio/common_audio.gyp:common_audio_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'common_video_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'common_video_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)common_video_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/common_video/common_video_unittests.gyp:common_video_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'modules_tests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'modules_tests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)modules_tests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/modules/modules.gyp:modules_tests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'modules_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'modules_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)modules_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/modules/modules.gyp:modules_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'system_wrappers_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'system_wrappers_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)system_wrappers_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/system_wrappers/source/system_wrappers_tests.gyp:system_wrappers_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'test_support_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'test_support_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)test_support_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/test/test.gyp:test_support_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'tools_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'tools_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)tools_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/tools/tools.gyp:tools_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'video_engine_core_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'video_engine_core_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_engine_core_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/video_engine/video_engine.gyp:video_engine_core_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'video_engine_tests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'video_engine_tests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_engine_tests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/webrtc.gyp:video_engine_tests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-     },
-     {
-      'target_name': 'voice_engine_unittests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'voice_engine_unittests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)voice_engine_unittests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/voice_engine/voice_engine.gyp:voice_engine_unittests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'webrtc_perf_tests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'webrtc_perf_tests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)webrtc_perf_tests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/webrtc.gyp:webrtc_perf_tests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'audio_codec_speed_tests_apk',
-      'type': 'none',
-      'variables': {
-        'test_suite_name': 'audio_codec_speed_tests',
-        'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)audio_codec_speed_tests<(SHARED_LIB_SUFFIX)',
-      },
-      'dependencies': [
-        '<(webrtc_root)/modules/modules.gyp:audio_codec_speed_tests',
-      ],
-      'includes': [
-        '../../../build/apk_test.gypi',
-      ],
-    },
-    {
-      'target_name': 'video_capture_tests_apk',
-      'type': 'none',
-       'variables': {
-         'test_suite_name': 'video_capture_tests',
-         'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_capture_tests<(SHARED_LIB_SUFFIX)',
-       },
-       'dependencies': [
-         '<(webrtc_root)/modules/modules.gyp:video_capture_tests',
-         'video_capture_java',
-       ],
-       'includes': [
-         '../../../build/apk_test.gypi',
-       ],
-    },
-    {
-      # Used only by video_capture_tests_apk above, and impossible to use in the
-      # standalone build, which is why it's declared here instead of under
-      # modules/video_capture/ (to avoid the need for a forked _noop.gyp file
-      # like this file has; see comment at the top of this file).
-      'target_name': 'video_capture_java',
-      'type': 'none',
-      'variables': {
-        'java_in_dir': '<(webrtc_root)/modules/video_capture/android/java',
-      },
-      'includes': [
-        '../../../build/java.gypi',
-      ],
-    },
-  ],
-}
-
-
diff --git a/webrtc/build/apk_tests_noop.gyp b/webrtc/build/apk_tests_noop.gyp
deleted file mode 100644
index 3523e79..0000000
--- a/webrtc/build/apk_tests_noop.gyp
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
-#
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file in the root of the source
-# tree. An additional intellectual property rights grant can be found
-# in the file PATENTS.  All contributing project authors may
-# be found in the AUTHORS file in the root of the source tree.
-
-# See webrtc/build/apk_tests.gyp for more information about this file.
-{
-  'targets': [
-    {
-      'target_name': 'audio_decoder_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'common_audio_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'common_video_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'modules_tests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'modules_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'system_wrappers_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'test_support_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'tools_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'video_engine_core_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'video_engine_tests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'voice_engine_unittests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'webrtc_perf_tests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'audio_codec_speed_tests_apk',
-      'type': 'none',
-    },
-    {
-      'target_name': 'video_capture_tests_apk',
-      'type': 'none',
-    },
-  ],
-}
diff --git a/webrtc/build/common.gypi b/webrtc/build/common.gypi
index 00bd4d4..8376ef8 100644
--- a/webrtc/build/common.gypi
+++ b/webrtc/build/common.gypi
@@ -23,13 +23,11 @@
           ['build_with_chromium==1', {
             'build_with_libjingle': 1,
             'webrtc_root%': '<(DEPTH)/third_party/webrtc',
-            'apk_tests_path%': '<(DEPTH)/third_party/webrtc/build/apk_tests.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/third_party/webrtc/modules/modules_java_chromium.gyp',
             'gen_core_neon_offsets_gyp%': '<(DEPTH)/third_party/webrtc/modules/audio_processing/gen_core_neon_offsets_chromium.gyp',
           }, {
             'build_with_libjingle%': 0,
             'webrtc_root%': '<(DEPTH)/webrtc',
-            'apk_tests_path%': '<(DEPTH)/webrtc/build/apk_test_noop.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/webrtc/modules/modules_java.gyp',
             'gen_core_neon_offsets_gyp%':'<(DEPTH)/webrtc/modules/audio_processing/gen_core_neon_offsets.gyp',
           }],
@@ -38,7 +36,6 @@
       'build_with_chromium%': '<(build_with_chromium)',
       'build_with_libjingle%': '<(build_with_libjingle)',
       'webrtc_root%': '<(webrtc_root)',
-      'apk_tests_path%': '<(apk_tests_path)',
       'modules_java_gyp_path%': '<(modules_java_gyp_path)',
       'gen_core_neon_offsets_gyp%': '<(gen_core_neon_offsets_gyp)',
       'webrtc_vp8_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp8',
@@ -48,7 +45,6 @@
     'build_with_chromium%': '<(build_with_chromium)',
     'build_with_libjingle%': '<(build_with_libjingle)',
     'webrtc_root%': '<(webrtc_root)',
-    'apk_tests_path%': '<(apk_tests_path)',
     'modules_java_gyp_path%': '<(modules_java_gyp_path)',
     'gen_core_neon_offsets_gyp%': '<(gen_core_neon_offsets_gyp)',
     'webrtc_vp8_dir%': '<(webrtc_vp8_dir)',
diff --git a/webrtc/common_audio/common_audio.gyp b/webrtc/common_audio/common_audio.gyp
index ae3bacb..699a7eb 100644
--- a/webrtc/common_audio/common_audio.gyp
+++ b/webrtc/common_audio/common_audio.gyp
@@ -228,9 +228,7 @@
             'wav_writer_unittest.cc',
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -239,15 +237,20 @@
         },
       ],  # targets
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are using
-        # Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'common_audio_unittests_apk_target',
+              'target_name': 'common_audio_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'common_audio_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)common_audio_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):common_audio_unittests_apk',
+                'common_audio_unittests',
+              ],
+              'includes': [
+                '../../build/apk_test.gypi',
               ],
             },
           ],
diff --git a/webrtc/common_video/common_video_unittests.gyp b/webrtc/common_video/common_video_unittests.gyp
index 91a11ed..b839e85 100644
--- a/webrtc/common_video/common_video_unittests.gyp
+++ b/webrtc/common_video/common_video_unittests.gyp
@@ -30,9 +30,7 @@
         4267,  # size_t to int truncation.
       ],
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are
-        # using Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'dependencies': [
             '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
           ],
@@ -41,15 +39,20 @@
     },
   ],  # targets
   'conditions': [
-    # TODO(henrike): remove build_with_chromium==1 when the bots are using
-    # Chromium's buildbots.
-    ['build_with_chromium==1 and OS=="android"', {
+    ['OS=="android"', {
       'targets': [
         {
-          'target_name': 'common_video_unittests_apk_target',
+          'target_name': 'common_video_unittests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'common_video_unittests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)common_video_unittests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):common_video_unittests_apk',
+            'common_video_unittests',
+          ],
+          'includes': [
+            '../../build/apk_test.gypi',
           ],
         },
       ],
diff --git a/webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_tests.gypi b/webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_tests.gypi
index 4d675e1..30a8715 100644
--- a/webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_tests.gypi
+++ b/webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_tests.gypi
@@ -26,9 +26,7 @@
       '<(webrtc_root)/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc',
     ],
     'conditions': [
-      # TODO(henrike): remove build_with_chromium==1 when the bots are
-      # using Chromium's buildbots.
-      ['build_with_chromium==1 and OS=="android"', {
+      ['OS=="android"', {
         'dependencies': [
           '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
         ],
@@ -36,15 +34,20 @@
     ],
   }],
   'conditions': [
-    # TODO(henrike): remove build_with_chromium==1 when the bots are using
-    # Chromium's buildbots.
-    ['build_with_chromium==1 and OS=="android"', {
+    ['OS=="android"', {
       'targets': [
         {
-          'target_name': 'audio_codec_speed_tests_apk_target',
+          'target_name': 'audio_codec_speed_tests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'audio_codec_speed_tests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)audio_codec_speed_tests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):audio_codec_speed_tests_apk',
+            'audio_codec_speed_tests',
+          ],
+          'includes': [
+            '../../../../../build/apk_test.gypi',
           ],
         },
       ],
diff --git a/webrtc/modules/audio_coding/neteq/neteq.gypi b/webrtc/modules/audio_coding/neteq/neteq.gypi
index 21ccee4..2bdb359 100644
--- a/webrtc/modules/audio_coding/neteq/neteq.gypi
+++ b/webrtc/modules/audio_coding/neteq/neteq.gypi
@@ -157,9 +157,7 @@
             'interface/audio_decoder.h',
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -200,15 +198,20 @@
         }, # neteq_unittest_tools
       ], # targets
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are using
-        # Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'audio_decoder_unittests_apk_target',
+              'target_name': 'audio_decoder_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'audio_decoder_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)audio_decoder_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):audio_decoder_unittests_apk',
+                'audio_decoder_unittests',
+              ],
+              'includes': [
+                '../../../../build/apk_test.gypi',
               ],
             },
           ],
diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp
index 138c73b..426ab08 100644
--- a/webrtc/modules/modules.gyp
+++ b/webrtc/modules/modules.gyp
@@ -356,9 +356,7 @@
             'video_coding/codecs/vp8/test/vp8_impl_unittest.cc',
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -367,22 +365,34 @@
         },
       ],
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are using
-        # Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'modules_unittests_apk_target',
+              'target_name': 'modules_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'modules_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)modules_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):modules_unittests_apk',
+                'modules_unittests',
+              ],
+              'includes': [
+                '../../build/apk_test.gypi',
               ],
             },
             {
-              'target_name': 'modules_tests_apk_target',
+              'target_name': 'modules_tests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'modules_tests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)modules_tests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):modules_tests_apk',
+                'modules_tests',
+              ],
+              'includes': [
+                '../../build/apk_test.gypi',
               ],
             },
           ],
diff --git a/webrtc/modules/video_capture/video_capture.gypi b/webrtc/modules/video_capture/video_capture.gypi
index 7382a1c..b32e30c 100644
--- a/webrtc/modules/video_capture/video_capture.gypi
+++ b/webrtc/modules/video_capture/video_capture.gypi
@@ -140,14 +140,35 @@
     },
   ],
   'conditions': [
-    ['include_tests==1 and build_with_chromium==1 and OS=="android"', {
-      # Use WebRTC capture code for Android APK tests that are built from a
-      # Chromium checkout. Normally when built as a part of Chromium the
-      # Chromium video capture code is used. This overrides the default in
-      # webrtc/build/common.gypi.
-      'variables': {
-        'include_internal_video_capture': 1,
-      },
+    ['include_tests==1 and OS=="android"', {
+      'targets': [
+        {
+          'target_name': 'video_capture_tests_apk',
+          'type': 'none',
+          'variables': {
+            'test_suite_name': 'video_capture_tests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_capture_tests<(SHARED_LIB_SUFFIX)',
+          },
+          'dependencies': [
+            'video_capture_tests',
+            'video_capture_java',
+          ],
+          'includes': [
+            '../../../build/apk_test.gypi',
+          ],
+        },
+        {
+          # Used only by video_capture_tests_apk above.
+          'target_name': 'video_capture_java',
+          'type': 'none',
+          'variables': {
+            'java_in_dir': '<(webrtc_root)/modules/video_capture/android/java',
+          },
+          'includes': [
+            '../../../build/java.gypi',
+          ],
+        },
+      ],
     }],
     ['include_tests==1', {
       'targets': [
diff --git a/webrtc/system_wrappers/source/system_wrappers_tests.gyp b/webrtc/system_wrappers/source/system_wrappers_tests.gyp
index 3d08c0d..29ac602 100644
--- a/webrtc/system_wrappers/source/system_wrappers_tests.gyp
+++ b/webrtc/system_wrappers/source/system_wrappers_tests.gyp
@@ -45,9 +45,7 @@
         ['os_posix==0', {
           'sources!': [ 'thread_posix_unittest.cc', ],
         }],
-        # TODO(henrike): remove build_with_chromium==1 when the bots are
-        # using Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'dependencies': [
             '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
           ],
@@ -60,15 +58,20 @@
     },
   ],
   'conditions': [
-    # TODO(henrike): remove build_with_chromium==1 when the bots are using
-    # Chromium's buildbots.
-    ['include_tests==1 and build_with_chromium==1 and OS=="android"', {
+    ['OS=="android"', {
       'targets': [
         {
-          'target_name': 'system_wrappers_unittests_apk_target',
+          'target_name': 'system_wrappers_unittests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'system_wrappers_unittests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)system_wrappers_unittests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):system_wrappers_unittests_apk',
+            'system_wrappers_unittests',
+          ],
+          'includes': [
+            '../../../build/apk_test.gypi',
           ],
         },
       ],
diff --git a/webrtc/test/test.gyp b/webrtc/test/test.gyp
index 69776e7..0514e37 100644
--- a/webrtc/test/test.gyp
+++ b/webrtc/test/test.gyp
@@ -191,9 +191,7 @@
         4267,  # size_t to int truncation.
       ],
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are
-        # using Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'dependencies': [
             '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
           ],
@@ -226,15 +224,20 @@
         },  # target buildbot_tests_scripts
       ],
     }],
-    # TODO(henrike): remove build_with_chromium==1 when the bots are using
-    # Chromium's buildbots.
-    ['include_tests==1 and build_with_chromium==1 and OS=="android"', {
+    ['OS=="android"', {
       'targets': [
         {
-          'target_name': 'test_support_unittests_apk_target',
+          'target_name': 'test_support_unittests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'test_support_unittests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)test_support_unittests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):test_support_unittests_apk',
+            'test_support_unittests',
+          ],
+          'includes': [
+            '../../build/apk_test.gypi',
           ],
         },
       ],
diff --git a/webrtc/tools/tools.gyp b/webrtc/tools/tools.gyp
index ee2a11d..0a38c90 100644
--- a/webrtc/tools/tools.gyp
+++ b/webrtc/tools/tools.gyp
@@ -135,9 +135,7 @@
             4267,  # size_t to int truncation.
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -145,16 +143,21 @@
           ],
         }, # tools_unittests
       ], # targets
-      # TODO(henrike): remove build_with_chromium==1 when the bots are using
-      # Chromium's buildbots.
       'conditions': [
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'tools_unittests_apk_target',
+              'target_name': 'tools_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'tools_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)tools_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):tools_unittests_apk',
+                'tools_unittests',
+              ],
+              'includes': [
+                '../../build/apk_test.gypi',
               ],
             },
           ],
diff --git a/webrtc/video_engine/video_engine_core.gypi b/webrtc/video_engine/video_engine_core.gypi
index ce9d536..76c7018 100644
--- a/webrtc/video_engine/video_engine_core.gypi
+++ b/webrtc/video_engine/video_engine_core.gypi
@@ -136,9 +136,7 @@
             'vie_remb_unittest.cc',
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -147,17 +145,22 @@
         },
       ], # targets
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are using
-        # Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'video_engine_core_unittests_apk_target',
+              'target_name': 'video_engine_core_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'video_engine_core_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_engine_core_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):video_engine_core_unittests_apk',
+                'video_engine_core_unittests',
               ],
-            },
+              'includes': [
+                '../../build/apk_test.gypi',
+              ],
+             },
           ],
         }],
         ['test_isolation_mode != "noop"', {
diff --git a/webrtc/voice_engine/voice_engine.gyp b/webrtc/voice_engine/voice_engine.gyp
index 43296ff..99a7886 100644
--- a/webrtc/voice_engine/voice_engine.gyp
+++ b/webrtc/voice_engine/voice_engine.gyp
@@ -132,9 +132,7 @@
             'voe_codec_unittest.cc',
           ],
           'conditions': [
-            # TODO(henrike): remove build_with_chromium==1 when the bots are
-            # using Chromium's buildbots.
-            ['build_with_chromium==1 and OS=="android"', {
+            ['OS=="android"', {
               'dependencies': [
                 '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
               ],
@@ -274,15 +272,20 @@
             },
           ],  # targets
         }],
-        # TODO(henrike): remove build_with_chromium==1 when the bots are using
-        # Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'targets': [
             {
-              'target_name': 'voice_engine_unittests_apk_target',
+              'target_name': 'voice_engine_unittests_apk',
               'type': 'none',
+              'variables': {
+                'test_suite_name': 'voice_engine_unittests',
+                'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)voice_engine_unittests<(SHARED_LIB_SUFFIX)',
+              },
               'dependencies': [
-                '<(apk_tests_path):voice_engine_unittests_apk',
+                'voice_engine_unittests',
+              ],
+              'includes': [
+                '../../build/apk_test.gypi',
               ],
             },
           ],
diff --git a/webrtc/webrtc.gyp b/webrtc/webrtc.gyp
index 96ae6a9..e5e9cc5 100644
--- a/webrtc/webrtc.gyp
+++ b/webrtc/webrtc.gyp
@@ -53,11 +53,6 @@
             'webrtc_tests',
           ],
         }],
-        ['build_with_chromium==0 and OS=="android"', {
-          'dependencies': [
-            '../tools/android/android_tools_precompiled.gyp:*',
-          ],
-        }],
       ],
     },
     {
diff --git a/webrtc/webrtc_tests.gypi b/webrtc/webrtc_tests.gypi
index ace6684..c8c0679 100644
--- a/webrtc/webrtc_tests.gypi
+++ b/webrtc/webrtc_tests.gypi
@@ -117,9 +117,7 @@
         'webrtc',
       ],
       'conditions': [
-        # TODO(henrike): remove build_with_chromium==1 when the bots are
-        # using Chromium's buildbots.
-        ['build_with_chromium==1 and OS=="android"', {
+        ['OS=="android"', {
           'dependencies': [
             '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
           ],
@@ -128,22 +126,34 @@
     },
   ],
   'conditions': [
-    # TODO(henrike): remove build_with_chromium==1 when the bots are using
-    # Chromium's buildbots.
-    ['build_with_chromium==1 and OS=="android"', {
+    ['OS=="android"', {
       'targets': [
         {
-          'target_name': 'video_engine_tests_apk_target',
+          'target_name': 'video_engine_tests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'video_engine_tests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)video_engine_tests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):video_engine_tests_apk',
+            'video_engine_tests',
+          ],
+          'includes': [
+            '../build/apk_test.gypi',
           ],
         },
         {
-          'target_name': 'webrtc_perf_tests_apk_target',
+          'target_name': 'webrtc_perf_tests_apk',
           'type': 'none',
+          'variables': {
+            'test_suite_name': 'webrtc_perf_tests',
+            'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)webrtc_perf_tests<(SHARED_LIB_SUFFIX)',
+          },
           'dependencies': [
-            '<(apk_tests_path):webrtc_perf_tests_apk',
+            'webrtc_perf_tests',
+          ],
+          'includes': [
+            '../build/apk_test.gypi',
           ],
         },
       ],