use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class SdkQuickfixUtils method getSdkHandler.
private static AndroidSdkHandler getSdkHandler() {
AndroidSdkData data = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (data == null) {
String title = "SDK Problem";
String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
Messages.showErrorDialog(msg, title);
return null;
}
return data.getSdkHandler();
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
myApiSensitiveTemplate = true;
if (!ourValidatedTemplateManager) {
ourValidatedTemplateManager = true;
File templateRootFolder = TemplateManager.getTemplateRootFolder();
if (templateRootFolder == null) {
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData == null) {
fail("Couldn't find SDK manager");
} else {
System.out.println("getTestSdkPath= " + TestUtils.getSdk());
System.out.println("getPlatformDir=" + TestUtils.getLatestAndroidPlatform());
String location = sdkData.getLocation().getPath();
System.out.println("Using SDK at " + location);
VersionCheck.VersionCheckResult result = VersionCheck.checkVersion(location);
System.out.println("Version check=" + result.getRevision());
File file = new File(location);
if (!file.exists()) {
System.out.println("SDK doesn't exist");
} else {
File folder = new File(location, FD_TOOLS + File.separator + FD_TEMPLATES);
boolean exists = folder.exists();
System.out.println("Template folder exists=" + exists + " for " + folder);
}
}
}
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class AvdWizardUtils method resolveSkinPath.
@Nullable
public static File resolveSkinPath(@Nullable File path, @Nullable SystemImageDescription image, @NotNull FileOp fop) {
if (path == null || path.getPath().isEmpty()) {
return path;
}
if (FileUtil.filesEqual(path, NO_SKIN)) {
return NO_SKIN;
}
if (!path.isAbsolute()) {
if (image != null) {
File[] skins = image.getSkins();
for (File skin : skins) {
if (skin.getPath().endsWith(File.separator + path.getPath())) {
return skin;
}
}
}
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
File dest = null;
if (sdkData != null) {
File sdkDir = sdkData.getLocation();
File sdkSkinDir = new File(sdkDir, "skins");
dest = new File(sdkSkinDir, path.getPath());
if (fop.exists(dest)) {
return dest;
}
}
File resourceDir = DeviceArtDescriptor.getBundledDescriptorsFolder();
if (resourceDir != null) {
File resourcePath = new File(resourceDir, path.getPath());
if (!fop.exists(resourcePath)) {
String name = resourcePath.getName();
// Unfortunately these have a different name than that included in the system images, so remap if necessary.
if (name.equals("AndroidWearSquare")) {
resourcePath = new File(resourcePath.getParent(), "wear_square");
}
if (name.equals("AndroidWearRound")) {
resourcePath = new File(resourcePath.getParent(), "wear_round");
}
}
if (fop.exists(resourcePath)) {
if (dest != null) {
try {
// Convert from webp to png here since emulator appears not to support it
fop.mkdirs(dest);
// Convert skin files (which are in webp format) to PNG for older versions of the emulator?
// As of 25.2.3, emulator supports webp directly.
AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
if (!emulatorSupportsWebp(sdkHandler)) {
convertWebpSkinToPng(fop, dest, resourcePath);
} else {
// Normal copy
for (File src : fop.listFiles(resourcePath)) {
File target = new File(dest, src.getName());
if (fop.isFile(src) && !fop.exists(target)) {
fop.copyFile(src, target);
}
}
}
return dest;
} catch (IOException e) {
getLog().warn(String.format("Failed to copy skin directory to %1$s, using studio-relative path %2$s", dest, resourcePath));
}
}
return resourcePath;
}
}
}
return path;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class SdksCleanupStep method cleanUpSdk.
public void cleanUpSdk(@NotNull Module module, @NotNull Collection<Sdk> invalidAndroidSdks) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet == null || androidFacet.getAndroidModel() == null) {
return;
}
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && !invalidAndroidSdks.contains(sdk) && (isMissingAndroidLibrary(sdk) || shouldRemoveAnnotationsJar(sdk))) {
// First try to recreate SDK; workaround for issue 78072
AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
if (additionalData != null && sdkData != null) {
IAndroidTarget target = additionalData.getBuildTarget(sdkData);
if (target == null) {
AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
StudioLoggerProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
sdkHandler.getSdkManager(logger).loadSynchronously(0, logger, null, null);
target = sdkHandler.getAndroidTargetManager(logger).getTargetFromHashString(additionalData.getBuildTargetHashString(), logger);
}
if (target != null) {
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeAllRoots();
for (OrderRoot orderRoot : myAndroidSdks.getLibraryRootsForTarget(target, sdk, true)) {
sdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
}
attachJdkAnnotations(sdkModificator);
sdkModificator.commitChanges();
}
}
// above workaround deals with)
if (isMissingAndroidLibrary(sdk)) {
invalidAndroidSdks.add(sdk);
}
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class AndroidLintOldTargetApiInspection method getHighestApi.
private static int getHighestApi(PsiElement element) {
int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
AndroidFacet instance = AndroidFacet.getInstance(element);
if (instance != null) {
AndroidSdkData sdkData = instance.getSdkData();
if (sdkData != null) {
for (IAndroidTarget target : sdkData.getTargets()) {
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
if (version.getApiLevel() > max && !version.isPreview()) {
max = version.getApiLevel();
}
}
}
}
}
return max;
}
Aggregations