Bug 1344244 - Part 2: Merge similar code into android.py. r=glandium
authorNick Alexander <nalexander@mozilla.com>
Wed, 05 Jul 2017 14:02:58 -0700
changeset 418214 01b0a01a38b1355ae9626308f1fb22be93b5acd9
parent 418213 7c127a4f904a704de6ee521ec50749d4dd1ebb6c
child 418215 0bae2cd791690a4ed325dc651c5cdf2d113b7f80
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1344244
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1344244 - Part 2: Merge similar code into android.py. r=glandium This refactoring unifies similar code that has been copy-pasted and subsequently diverged. MozReview-Commit-ID: EuVQBR4gsDo
python/mozboot/mozboot/android.py
python/mozboot/mozboot/archlinux.py
python/mozboot/mozboot/centosfedora.py
python/mozboot/mozboot/debian.py
python/mozboot/mozboot/osx.py
--- a/python/mozboot/mozboot/android.py
+++ b/python/mozboot/mozboot/android.py
@@ -189,16 +189,55 @@ def install_mobile_android_sdk_or_ndk(ur
             subprocess.check_call(cmd, stdout=stdout)
 
         print('Unpacking %s... DONE' % abspath)
 
     finally:
         os.chdir(old_path)
 
 
+def get_paths(os_name):
+    mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH',
+                                   os.path.expanduser(os.path.join('~', '.mozbuild')))
+    sdk_path = os.environ.get('ANDROID_SDK_HOME',
+                              os.path.join(mozbuild_path, 'android-sdk-{}'.format(os_name)))
+    ndk_path = os.environ.get('ANDROID_NDK_HOME',
+                              os.path.join(mozbuild_path, 'android-ndk-r11c'))
+    return (mozbuild_path, sdk_path, ndk_path)
+
+
+def ensure_android(os_name, artifact_mode):
+    '''
+    Ensure the Android SDK (and NDK, if `artifact_mode` is falsy) are
+    installed.  If not, fetch and unpack the SDK and/or NDK from the
+    given URLs.  Ensure the required Android SDK packages are
+    installed.
+
+    `os_name` can be 'linux' or 'macosx'.
+    '''
+    # The user may have an external Android SDK (in which case we
+    # save them a lengthy download), or they may have already
+    # completed the download. We unpack to
+    # ~/.mozbuild/{android-sdk-$OS_NAME, android-ndk-r11c}.
+    mozbuild_path, sdk_path, ndk_path = get_paths(os_name)
+    ext = 'zip' if os_name == 'macosx' else 'tgz'
+    sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-{}.{}'.format(os_name, ext)
+    ndk_url = android_ndk_url(os_name)
+
+    ensure_android_sdk_and_ndk(path=mozbuild_path,
+                               sdk_path=sdk_path, sdk_url=sdk_url,
+                               ndk_path=ndk_path, ndk_url=ndk_url,
+                               artifact_mode=artifact_mode)
+
+    # We expect the |android| tool to be at
+    # ~/.mozbuild/android-sdk-$OS_NAME/tools/android.
+    android_tool = os.path.join(sdk_path, 'tools', 'android')
+    ensure_android_packages(android_tool=android_tool)
+
+
 def ensure_android_sdk_and_ndk(path, sdk_path, sdk_url, ndk_path, ndk_url, artifact_mode):
     '''
     Ensure the Android SDK and NDK are found at the given paths.  If not, fetch
     and unpack the SDK and/or NDK from the given URLs into |path|.
     '''
 
     # It's not particularly bad to overwrite the NDK toolchain, but it does take
     # a while to unpack, so let's avoid the disk activity if possible.  The SDK
@@ -246,25 +285,31 @@ def ensure_android_packages(android_tool
     # Bug 1171232: The |android| tool behaviour has changed; we no longer can
     # see what packages are installed easily.  Don't check until we find a way
     # to actually verify.
     failing = []
     if failing:
         raise Exception(MISSING_ANDROID_PACKAGES % (', '.join(missing), ', '.join(failing)))
 
 
-def suggest_mozconfig(sdk_path=None, ndk_path=None, artifact_mode=False):
+def suggest_mozconfig(os_name, artifact_mode=False):
+    _mozbuild_path, sdk_path, ndk_path = get_paths(os_name)
     if artifact_mode:
         print(MOBILE_ANDROID_ARTIFACT_MODE_MOZCONFIG_TEMPLATE % (sdk_path))
     else:
         print(MOBILE_ANDROID_MOZCONFIG_TEMPLATE % (sdk_path, ndk_path))
 
 
 def android_ndk_url(os_name, ver='r11c'):
-    # Produce a URL like 'https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
+    # Produce a URL like
+    # 'https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
     base_url = 'https://dl.google.com/android/repository/android-ndk'
 
+    if os_name == 'macosx':
+        # |mach bootstrap| uses 'macosx', but Google uses 'darwin'.
+        os_name = 'darwin'
+
     if sys.maxsize > 2**32:
         arch = 'x86_64'
     else:
         arch = 'x86'
 
     return '%s-%s-%s-%s.zip' % (base_url, ver, os_name, arch)
--- a/python/mozboot/mozboot/archlinux.py
+++ b/python/mozboot/mozboot/archlinux.py
@@ -61,20 +61,23 @@ class ArchlinuxBootstrapper(StyloInstall
         'networkmanager',
     ]
 
     BROWSER_AUR_PACKAGES = [
         'https://aur.archlinux.org/cgit/aur.git/snapshot/uuid.tar.gz',
     ]
 
     MOBILE_ANDROID_COMMON_PACKAGES = [
-        'zlib',  # mobile/android requires system zlib.
-        'jdk7-openjdk', # It would be nice to handle alternative JDKs.  See https://wiki.archlinux.org/index.php/Java.
-        'wget',  # For downloading the Android SDK and NDK.
-        'multilib/lib32-libstdc++5', # See comment about 32 bit binaries and multilib below.
+        # It would be nice to handle alternative JDKs.  See
+        # https://wiki.archlinux.org/index.php/Java.
+        'jdk7-openjdk',
+        # For downloading the Android SDK and NDK.
+        'wget',
+        # See comment about 32 bit binaries and multilib below.
+        'multilib/lib32-libstdc++5',
         'multilib/lib32-ncurses',
         'multilib/lib32-readline',
         'multilib/lib32-zlib',
     ]
 
     def __init__(self, version, dist_id, **kwargs):
         print 'Using an experimental bootstrapper for Archlinux.'
         BaseBootstrapper.__init__(self, **kwargs)
@@ -95,58 +98,41 @@ class ArchlinuxBootstrapper(StyloInstall
         self.ensure_mobile_android_packages(artifact_mode=True)
 
     def ensure_browser_packages(self, artifact_mode=False):
         # TODO: Figure out what not to install for artifact mode
         self.aur_install(*self.BROWSER_AUR_PACKAGES)
         self.pacman_install(*self.BROWSER_PACKAGES)
 
     def ensure_mobile_android_packages(self, artifact_mode=False):
-        import android
-
         # Multi-part process:
         # 1. System packages.
-        # 2. Android SDK. Android NDK only if we are not in artifact mode.
-        # 3. Android packages.
+        # 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
 
         # 1. This is hard to believe, but the Android SDK binaries are 32-bit
         # and that conflicts with 64-bit Arch installations out of the box.  The
         # solution is to add the multilibs repository; unfortunately, this
         # requires manual intervention.
         try:
             self.pacman_install(*self.MOBILE_ANDROID_COMMON_PACKAGES)
-        except e:
+        except Exception as e:
             print('Failed to install all packages.  The Android developer '
                   'toolchain requires 32 bit binaries be enabled (see '
                   'https://wiki.archlinux.org/index.php/Android).  You may need to '
                   'manually enable the multilib repository following the instructions '
                   'at https://wiki.archlinux.org/index.php/Multilib.')
             raise e
 
-        # 2. The user may have an external Android SDK (in which case we save
-        # them a lengthy download), or they may have already completed the
-        # download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
-        mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
-        self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
-        self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
-        self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
-        self.ndk_url = android.android_ndk_url('linux')
-
-        android.ensure_android_sdk_and_ndk(path=mozbuild_path,
-                                           sdk_path=self.sdk_path, sdk_url=self.sdk_url,
-                                           ndk_path=self.ndk_path, ndk_url=self.ndk_url,
-                                           artifact_mode=artifact_mode)
-        android_tool = os.path.join(self.sdk_path, 'tools', 'android')
-        android.ensure_android_packages(android_tool=android_tool)
+        # 2. Android pieces.
+        import android
+        android.ensure_android('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_mozconfig(self, artifact_mode=False):
         import android
-        android.suggest_mozconfig(sdk_path=self.sdk_path,
-                                  ndk_path=self.ndk_path,
-                                  artifact_mode=artifact_mode)
+        android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_artifact_mode_mozconfig(self):
         self.suggest_mobile_android_mozconfig(artifact_mode=True)
 
     def _update_package_manager(self):
         self.pacman_update
 
     def upgrade_mercurial(self, current):
--- a/python/mozboot/mozboot/centosfedora.py
+++ b/python/mozboot/mozboot/centosfedora.py
@@ -1,13 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-import os
 import platform
 
 from mozboot.base import BaseBootstrapper
 from mozboot.linux_common import StyloInstall
 
 
 class CentOSFedoraBootstrapper(StyloInstall, BaseBootstrapper):
     def __init__(self, distro, version, dist_id, **kwargs):
@@ -104,45 +103,23 @@ class CentOSFedoraBootstrapper(StyloInst
         if self.distro in ('CentOS', 'CentOS Linux'):
             yasm = 'http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.i686.rpm'
             if platform.architecture()[0] == '64bit':
                 yasm = 'http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.x86_64.rpm'
 
             self.run_as_root(['rpm', '-ivh', yasm])
 
     def ensure_mobile_android_packages(self, artifact_mode=False):
-        import android
-
         # Install Android specific packages.
         self.dnf_install(*self.mobile_android_packages)
 
-        # Fetch Android SDK and NDK.
-        mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
-        self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
-        self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
-        self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
-        self.ndk_url = android.android_ndk_url('linux')
-
-        android.ensure_android_sdk_and_ndk(path=mozbuild_path,
-                                           sdk_path=self.sdk_path, sdk_url=self.sdk_url,
-                                           ndk_path=self.ndk_path, ndk_url=self.ndk_url,
-                                           artifact_mode=artifact_mode)
-
-        # Most recent version of build-tools appears to be 23.0.1 on Fedora
-        packages = [p for p in android.ANDROID_PACKAGES if not p.startswith('build-tools')]
-        packages.append('build-tools-23.0.1')
-
-        # 3. We expect the |android| tool to be at
-        # ~/.mozbuild/android-sdk-linux/tools/android.
-        android_tool = os.path.join(self.sdk_path, 'tools', 'android')
-        android.ensure_android_packages(android_tool=android_tool, packages=packages)
+        import android
+        android.ensure_android('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_mozconfig(self, artifact_mode=False):
         import android
-        android.suggest_mozconfig(sdk_path=self.sdk_path,
-                                  ndk_path=self.ndk_path,
-                                  artifact_mode=artifact_mode)
+        android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_artifact_mode_mozconfig(self):
         self.suggest_mobile_android_mozconfig(artifact_mode=True)
 
     def upgrade_mercurial(self, current):
         self.dnf_update('mercurial')
--- a/python/mozboot/mozboot/debian.py
+++ b/python/mozboot/mozboot/debian.py
@@ -1,15 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-import os
-import sys
-
 from mozboot.base import BaseBootstrapper
 from mozboot.linux_common import StyloInstall
 
 
 MERCURIAL_INSTALL_PROMPT = '''
 Mercurial releases a new version every 3 months and your distro's package
 may become out of date. This may cause incompatibility with some
 Mercurial extensions that rely on new Mercurial features. As a result,
@@ -69,37 +66,35 @@ class DebianBootstrapper(StyloInstall, B
     ]
 
     # Subclasses can add packages to this variable to have them installed.
     BROWSER_DISTRO_PACKAGES = []
 
     # These are common packages for building Firefox for Android
     # (mobile/android) for all Debian-derived distros (such as Ubuntu).
     MOBILE_ANDROID_COMMON_PACKAGES = [
-        'zlib1g-dev',  # mobile/android requires system zlib.
         'default-jdk',
         'wget',  # For downloading the Android SDK and NDK.
         'libncurses5:i386',  # See comments about i386 below.
         'libstdc++6:i386',
-        'zlib1g:i386',
     ]
 
     # Subclasses can add packages to this variable to have them installed.
     MOBILE_ANDROID_DISTRO_PACKAGES = []
 
     def __init__(self, version, dist_id, **kwargs):
         BaseBootstrapper.__init__(self, **kwargs)
 
         self.version = version
         self.dist_id = dist_id
 
         self.packages = self.COMMON_PACKAGES + self.DISTRO_PACKAGES
         self.browser_packages = self.BROWSER_COMMON_PACKAGES + self.BROWSER_DISTRO_PACKAGES
-        self.mobile_android_packages = self.MOBILE_ANDROID_COMMON_PACKAGES + self.MOBILE_ANDROID_DISTRO_PACKAGES
-
+        self.mobile_android_packages = self.MOBILE_ANDROID_COMMON_PACKAGES + \
+                                       self.MOBILE_ANDROID_DISTRO_PACKAGES
 
     def install_system_packages(self):
         self.apt_install(*self.packages)
 
     def install_browser_packages(self):
         self.ensure_browser_packages()
 
     def install_browser_artifact_mode_packages(self):
@@ -111,57 +106,37 @@ class DebianBootstrapper(StyloInstall, B
     def install_mobile_android_artifact_mode_packages(self):
         self.ensure_mobile_android_packages(artifact_mode=True)
 
     def ensure_browser_packages(self, artifact_mode=False):
         # TODO: Figure out what not to install for artifact mode
         self.apt_install(*self.browser_packages)
 
     def ensure_mobile_android_packages(self, artifact_mode=False):
-        import android
-
         # Multi-part process:
         # 1. System packages.
-        # 2. Android SDK. Android NDK only if we are not in artifact mode.
-        # 3. Android packages.
+        # 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
 
         # 1. This is hard to believe, but the Android SDK binaries are 32-bit
         # and that conflicts with 64-bit Debian and Ubuntu installations out of
         # the box.  The solution is to add the i386 architecture.  See
         # "Troubleshooting Ubuntu" at
         # http://developer.android.com/sdk/installing/index.html?pkg=tools.
         self.run_as_root(['dpkg', '--add-architecture', 'i386'])
         # After adding a new arch, the list of packages has to be updated
         self.apt_update()
         self.apt_install(*self.mobile_android_packages)
 
-        # 2. The user may have an external Android SDK (in which case we save
-        # them a lengthy download), or they may have already completed the
-        # download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
-        mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
-        self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
-        self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
-        self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
-        self.ndk_url = android.android_ndk_url('linux')
-
-        android.ensure_android_sdk_and_ndk(path=mozbuild_path,
-                                           sdk_path=self.sdk_path, sdk_url=self.sdk_url,
-                                           ndk_path=self.ndk_path, ndk_url=self.ndk_url,
-                                           artifact_mode=artifact_mode)
-
-        # 3. We expect the |android| tool to at
-        # ~/.mozbuild/android-sdk-linux/tools/android.
-        android_tool = os.path.join(self.sdk_path, 'tools', 'android')
-        android.ensure_android_packages(android_tool=android_tool)
+        # 2. Android pieces.
+        import android
+        android.ensure_android('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_mozconfig(self, artifact_mode=False):
         import android
-        android.suggest_mozconfig(sdk_path=self.sdk_path,
-                                  ndk_path=self.ndk_path,
-                                  artifact_mode=artifact_mode)
+        android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
 
     def suggest_mobile_android_artifact_mode_mozconfig(self):
         self.suggest_mobile_android_mozconfig(artifact_mode=True)
 
     def _update_package_manager(self):
         self.apt_update()
 
     def upgrade_mercurial(self, current):
--- a/python/mozboot/mozboot/osx.py
+++ b/python/mozboot/mozboot/osx.py
@@ -328,63 +328,43 @@ class OSXBootstrapper(BaseBootstrapper):
             ('yasm', 'yasm'),
             ('llvm', 'llvm'),
         ]
         self._ensure_homebrew_packages(packages)
 
     def ensure_homebrew_mobile_android_packages(self, artifact_mode=False):
         # Multi-part process:
         # 1. System packages.
-        # 2. Android SDK. Android NDK only if we are not in artifact mode.
-        # 3. Android packages.
-
-        import android
+        # 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
 
         # 1. System packages.
         packages = [
             ('brew-cask', 'caskroom/cask/brew-cask'),  # For installing Java later.
             ('wget', 'wget'),
         ]
         self._ensure_homebrew_packages(packages)
 
         casks = [
             ('java', 'java'),
         ]
         installed = self._ensure_homebrew_casks(casks)
         if installed:
             print(JAVA_LICENSE_NOTICE)  # We accepted a license agreement for the user.
 
-        # 2. The user may have an external Android SDK (in which case we save
-        # them a lengthy download), or they may have already completed the
-        # download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
-        mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
-        self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-macosx'))
-        self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
-        self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-macosx.zip'
         is_64bits = sys.maxsize > 2**32
-        if is_64bits:
-            self.ndk_url = android.android_ndk_url('darwin')
-        else:
+        if not is_64bits:
             raise Exception('You need a 64-bit version of Mac OS X to build Firefox for Android.')
 
-        android.ensure_android_sdk_and_ndk(path=mozbuild_path,
-                                           sdk_path=self.sdk_path, sdk_url=self.sdk_url,
-                                           ndk_path=self.ndk_path, ndk_url=self.ndk_url,
-                                           artifact_mode=artifact_mode)
-
-        # 3. We expect the |android| tool to at
-        # ~/.mozbuild/android-sdk-macosx/tools/android.
-        android_tool = os.path.join(self.sdk_path, 'tools', 'android')
-        android.ensure_android_packages(android_tool=android_tool)
+        # 2. Android pieces.
+        import android
+        android.ensure_android('macosx', artifact_mode=artifact_mode)
 
     def suggest_homebrew_mobile_android_mozconfig(self, artifact_mode=False):
         import android
-        android.suggest_mozconfig(sdk_path=self.sdk_path,
-                                  ndk_path=self.ndk_path,
-                                  artifact_mode=artifact_mode)
+        android.suggest_mozconfig('macosx', artifact_mode=artifact_mode)
 
     def _ensure_macports_packages(self, packages):
         self.port = self.which('port')
         assert self.port is not None
 
         installed = set(self.check_output([self.port, 'installed']).split())
 
         missing = [package for package in packages if package not in installed]
@@ -413,59 +393,41 @@ class OSXBootstrapper(BaseBootstrapper):
             'clang-4.0',
         ]
 
         self._ensure_macports_packages(packages)
 
     def ensure_macports_mobile_android_packages(self, artifact_mode=False):
         # Multi-part process:
         # 1. System packages.
-        # 2. Android SDK. Android NDK only if we are not in artifact mode.
-        # 3. Android packages.
-
-        import android
+        # 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
 
         # 1. System packages.
         packages = [
             'wget',
         ]
         self._ensure_macports_packages(packages)
 
         # Verify the presence of java and javac.
         if not self.which('java') or not self.which('javac'):
-            raise Exception('You need to have Java version 1.7 or later installed. Please visit http://www.java.com/en/download/mac_download.jsp to get the latest version.')
+            raise Exception('You need to have Java version 1.7 or later installed. '
+                            'Please visit http://www.java.com/en/download/mac_download.jsp '
+                            'to get the latest version.')
 
-        # 2. The user may have an external Android SDK (in which case we save
-        # them a lengthy download), or they may have already completed the
-        # download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11b}.
-        mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
-        self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-macosx'))
-        self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11b'))
-        self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-macosx.zip'
         is_64bits = sys.maxsize > 2**32
-        if is_64bits:
-            self.ndk_url = android.android_ndk_url('darwin')
-        else:
+        if not is_64bits:
             raise Exception('You need a 64-bit version of Mac OS X to build Firefox for Android.')
 
-        android.ensure_android_sdk_and_ndk(path=mozbuild_path,
-                                           sdk_path=self.sdk_path, sdk_url=self.sdk_url,
-                                           ndk_path=self.ndk_path, ndk_url=self.ndk_url,
-                                           artifact_mode=artifact_mode)
-
-        # 3. We expect the |android| tool to at
-        # ~/.mozbuild/android-sdk-macosx/tools/android.
-        android_tool = os.path.join(self.sdk_path, 'tools', 'android')
-        android.ensure_android_packages(android_tool=android_tool)
+        # 2. Android pieces.
+        import android
+        android.ensure_android('macosx', artifact_mode=artifact_mode)
 
     def suggest_macports_mobile_android_mozconfig(self, artifact_mode=False):
         import android
-        android.suggest_mozconfig(sdk_path=self.sdk_path,
-                                  ndk_path=self.ndk_path,
-                                  artifact_mode=artifact_mode)
+        android.suggest_mozconfig('macosx', artifact_mode=artifact_mode)
 
     def ensure_package_manager(self):
         '''
         Search package mgr in sys.path, if none is found, prompt the user to install one.
         If only one is found, use that one. If both are found, prompt the user to choose
         one.
         '''
         installed = []