rust-lang/rust · error · NameError

package not found: {name}

Error message

package not found: {name}

What it means

Raised by Lockfile.add() in android-sdk-manager.py at line 123 as a NameError when the requested package name is not found in the packages dict (which is populated by fetching and parsing Google's SDK repository XML files). The add() function is called when adding packages to the lockfile or resolving dependencies; if the name doesn't match any package path in any of the REPOSITORIES, it cannot proceed.

Source

Thrown at src/ci/docker/scripts/android-sdk-manager.py:123

    packages = {}
    for repo in REPOSITORIES:
        packages.update(fetch_repository(BASE_REPOSITORY, repo))
    return packages


class Lockfile:
    def __init__(self, path):
        self.path = path
        self.packages = {}
        if os.path.exists(path):
            with open(path) as f:
                for line in f:
                    path, url, sha1 = line.split(" ")
                    self.packages[path] = Package(path, url, sha1)

    def add(self, packages, name, *, update=True):
        if name not in packages:
            raise NameError("package not found: " + name)
        if not update and name in self.packages:
            return
        self.packages[name] = packages[name]
        for dep in packages[name].deps:
            self.add(packages, dep, update=False)

    def save(self):
        packages = list(sorted(self.packages.values(), key=lambda p: p.path))
        with open(self.path, "w") as f:
            for package in packages:
                f.write(package.path + " " + package.url + " " + package.sha1 + "\n")


def cli_add_to_lockfile(args):
    lockfile = Lockfile(args.lockfile)
    packages = fetch_repositories()
    for package in args.packages:
        lockfile.add(packages, package)

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. List available packages by running the official 'sdkmanager --list' or by inspecting the repository XMLs to find the exact path string.
  2. Correct the package name to match the exact 'path' attribute (note the ';' delimiter, e.g. 'platforms;android-33').
  3. If the package was renamed/removed, find its current name in the repository XML.
  4. Ensure all relevant REPOSITORIES entries are being fetched (some packages live in specific sub-repositories).

Example fix

# before: wrong package name format
python3 android-sdk-manager.py add-to-lockfile lock.txt 'android-33'
# after: use the exact path attribute
python3 android-sdk-manager.py add-to-lockfile lock.txt 'platforms;android-33'
Defensive patterns

Strategy: validation

Validate before calling

# Before calling Lockfile.add, verify the package exists
def package_exists(packages, name):
    if name not in packages:
        available = [k for k in packages if name.split(';')[0] in k]
        print(f'Package "{name}" not found.')
        if available:
            print(f'Similar packages: {available[:5]}')
        return False
    return True

Try / catch

try:
    lockfile.add(packages, package_name)
except NameError as e:
    if 'package not found' in str(e):
        print(f'Package "{package_name}" not in any repository.')
        print('Check the exact path from the repository XML.')
    raise

Prevention

When it happens

Trigger: Lockfile.add(packages, name) at line 121-123: 'if name not in packages' is True. The packages dict is built by fetch_repositories() which fetches BASE_REPOSITORY + each URL in REPOSITORIES, parses the XML, and maps path -> Package. The name argument must exactly match a 'path' attribute from a <remotePackage> element in one of those XMLs.

Common situations: Typo or incorrect package path format (e.g. using a human-readable name instead of the dotted path like 'platforms;android-33'); the package was removed or renamed by Google; the repository XML that contains the package wasn't fetched (e.g. only a subset of REPOSITORIES were queried); or using a package path format with wrong delimiters.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/3c3fd9ecbcb7a92b. Report an issue: GitHub.