Android: How to handle errors 'Could not connect to archive.ubuntu.com' and 'Failed to fetch https://packagecloud.io/github/git-lfs/ubuntu...' on Linux when fetching APT packages
Developers working on Linux stacks may encounter a series of errors when working with Development tools such as apt packages that can be resolved with a workaround script. The root cause of the issue is not always clear but the script has managed to resolve issues such as:
Cannot initiate the connection to archive.ubuntu.com:80
(2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the
connection to archive.ubuntu.com:80 (2001:67c:1562::18).
- connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16).
- connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19).
- connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (126.96.36.199),
connection timed out Could not connect to archive.ubuntu.com:80 (188.8.131.52),
connection timed out Could not connect to archive.ubuntu.com:80 (184.108.40.206),
connection timed out Could not connect to archive.ubuntu.com:80 (220.127.116.11),
connection timed out [IP: 18.104.22.168 80]
In the samples we collected, the error above was being observed from running:
apt update apt-get install xxx
Additionally, an error seen like the one below could also be seen on Linux stacks
E: Failed to fetch https://packagecloud.io/github/git-lfs/ubuntu/dists/focal/InRelease 402 Payment Required [IP: 22.214.171.124 443] E: The repository 'https://packagecloud.io/github/git-lfs/ubuntu focal InRelease' is not signed.
As you can see, these errors vary from indicating connection issue all the way to a payment issue on the third party's end.
The following script managed to resolve both of these issues when added before the failing script:
sudo rm -fv /etc/apt/sources.list.d/github_git-lfs.list
sudo rm -fv /etc/apt/sources.list.d/github_git-lfs.list.save
This command removes the files offering a "clean slate" for the build and its steps to be able to fetch the apt packages on the next time the build is run with this script.
Android cmdline-tools missing?
In the past we have seen some tickets from developers building Android projects encountering an issue that leads them to believe that cmdline-tools is missing from our stacks. The error for this will likely look like this:
Cannot run program "/usr/local/share/android-sdk/cmdline-tools/latest/bin/sdkmanager": error=2, No such file or directory
After checking our stacks running a script like sdkmanager --list we can confirm that cmdline-tools are installed, the issue instead was that the command that is failing to run the program fails due to the path it is trying to use.
The command is trying this path:
The path in our stacks for sdk manager is the following:
By understanding this, you can create a symlink with the following script:
ln -s /usr/local/share/android-sdk/cmdline-tools/cmdline-tools/bin/sdkmanager /usr/local/share/android-sdk/cmdline-tools/latest/bin/sdkmanager
Your symlink should now allow for the program to run on the correct path and cmdline-tools will be found 🙌