Robert
Robert

Reputation: 452

Android SDK: repositories.cfg is missing

I'm trying to setup my environment for android programming and I'm encountering this error:

./sdkmanager --update
Warning: File /home/user/.android/repositories.cfg could not be loaded.        
[=======================================] 100% Computing updates...

I have seen other threads where people say (or rather guess), I should just create that file. But I'm not the kind of guy who just changes a system upon guessing without having an overview of the consequences. I mean in this case it doesn't feel too wrong to do it but why does the sdkmanager not create that file if it needs it? I mean the sdkmanager has already created the hidden folder .android with so many files in it, what would let the devs think 'creating the file repositories.cfg is something to be careful about, let's not create it ourselves and warn the user'?

Upvotes: 3

Views: 28007

Answers (2)

Riad Krim
Riad Krim

Reputation: 954

Before attempting to explain, please notice that the message is displaying a Warning and not an Error. Warning: File repositories.cfg could not be loaded.

The reason this is just a warning is because this file is intended for users (developers) to add a list of sdk-repository sources.

Note that this file is a Properties file that contains one property per line in form of: KEY=VALUE

So sdkmanager has its own list of sdk-repository sources and lets you add yours in this file as a user level list.

Answers:

In some threads, I saw that answer to this question suggest to just create the repositories.cfg file:

mkdir -p ~/.android && touch ~/.android/repositories.cfg like here.

where other answer suggest to add the following lines after creating the file:

### User Sources for Android SDK Manager
count=0

like here, and both solutions work.

Why: To better understand what's happening we need to have a look at the source file that handles this part.

Here is a link to the RepoSources.java at the commit that introduces this behaviour. The file and behaviour might have changed over time but this will help understand what's happening.

// Line 35-39
String KEY_COUNT = "count";
String KEY_SRC = "src";
String SRC_FILENAME = "repositories.cfg";
ArrayList<RepoSource> mSources = new ArrayList<RepoSource>();

We will deal with the file repositories.cfg looking for keys count and src and add found sources to mSources array.

// Lines 71 - 120
public void loadUserSources()

Here (line 86-92) if the file exist, we load it as a Properties instance, then we look for the key count and if not found we return 0 otherwise later in code we look for src key to add found sources to the array.

So having or not a count key when the file is empty doesn't matter as it defaults to count=0.

You can notice that when this repositories.cfg file does not exit it does nothing, it doesn't even display the warning.

This means that at that time, developers were using this solution without even noticing that they could use repositories.cfg as nothing was displayed.

I hope this gives you the information you need.

Upvotes: 11

Noah
Noah

Reputation: 93

I've created the empty text file "repositories.cfg", and it's true, the error goes away, however nothing get downloaded as there are no repositories in the file. So that "solution" doesn't actually solve anything. It just hides the error, but fails to allow the sdk tools to download. Don't bother with it. My suggestion, download the full Android Studio and install it. Then pull out the parts you need into their own folder, and point to those in your system variables. Then you can uninstall Android Studio (if all you wanted were the tools, like me).

Upvotes: 1

Related Questions