The question doesn't seem to require a programmatic solution, but my Google search brought me here anyway. Here's my C# attempt at detecting where the SDK is installed, based on the most common installation paths.
static string FindAndroidSDKPath()
{
string uniqueFile = Path.Combine("platform-tools", "adb.exe"); // look for adb in Android folders
string[] searchDirs =
{
// User/AppData/Local
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
// Program Files
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
// Program Files (x86) (it's okay if we're on 32-bit, we check if this folder exists first)
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + " (x86)",
// User/AppData/Roaming
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
};
foreach (string searchDir in searchDirs)
{
string androidDir = Path.Combine(searchDir, "Android");
if (Directory.Exists(androidDir))
{
string[] subDirs = Directory.GetDirectories(androidDir, "*sdk*", SearchOption.TopDirectoryOnly);
foreach (string subDir in subDirs)
{
string path = Path.Combine(subDir, uniqueFile);
if (File.Exists(path))
{
// found unique file at DIR/Android
return subDir;
}
}
}
}
// no luck finding SDK! :(
return null;
}
I need this because I'm writing an extension to a C# program to work with Android Studio/Gradle. Hopefully someone else will find this approach useful.
C:\Users\**username**\AppData\Local\Android\sdk
– Swedenborgian