use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class SkinChooser method getSkins.
private List<File> getSkins() {
List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
Set<File> result = Sets.newTreeSet();
for (Device device : devices) {
File skinFile = AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), null, FileOpUtils.create());
if (skinFile != null && skinFile.exists()) {
result.add(skinFile);
}
}
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(SkinChooser.class);
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
for (IAndroidTarget target : sdkHandler.getAndroidTargetManager(progress).getTargets(progress)) {
Arrays.stream(target.getSkins()).map(this::resolve).forEach(result::add);
}
for (ISystemImage img : sdkHandler.getSystemImageManager(progress).getImages()) {
Arrays.stream(img.getSkins()).map(this::resolve).forEach(result::add);
}
List<File> resultList = Lists.newArrayList();
resultList.add(NO_SKIN);
resultList.addAll(result);
return resultList;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidVersionsInfo method getCompilationTargets.
/**
* @return a list of android compilation targets (platforms and add-on SDKs)
*/
@NotNull
private static IAndroidTarget[] getCompilationTargets() {
AndroidTargetManager targetManager = AndroidSdks.getInstance().tryToChooseSdkHandler().getAndroidTargetManager(REPO_LOG);
List<IAndroidTarget> result = Lists.newArrayList();
for (IAndroidTarget target : targetManager.getTargets(REPO_LOG)) {
if (target.isPlatform()) {
result.add(target);
}
}
return result.toArray(new IAndroidTarget[result.size()]);
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class GraphicsLayoutRenderer method create.
@VisibleForTesting
@NotNull
static GraphicsLayoutRenderer create(@NotNull AndroidFacet facet, @NotNull AndroidPlatform platform, @NotNull Project project, @NotNull Configuration configuration, @NotNull ILayoutPullParser parser, @Nullable Color backgroundColor, @NotNull SessionParams.RenderingMode renderingMode, boolean useSecurityManager) throws InitializationException {
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
LayoutLibrary layoutLib;
try {
IAndroidTarget latestTarget = configuration.getConfigurationManager().getHighestApiTarget();
if (latestTarget == null) {
throw new UnsupportedLayoutlibException("GraphicsLayoutRenderer requires at least layoutlib version " + MIN_LAYOUTLIB_API_VERSION);
}
layoutLib = platform.getSdkData().getTargetData(latestTarget).getLayoutLibrary(project);
if (layoutLib == null) {
throw new InitializationException("getLayoutLibrary() returned null");
}
} catch (RenderingException e) {
throw new InitializationException(e);
} catch (IOException e) {
throw new InitializationException(e);
}
if (layoutLib.getApiLevel() < MIN_LAYOUTLIB_API_VERSION) {
throw new UnsupportedLayoutlibException("GraphicsLayoutRenderer requires at least layoutlib version " + MIN_LAYOUTLIB_API_VERSION);
}
AppResourceRepository appResources = AppResourceRepository.getAppResources(facet, true);
final Module module = facet.getModule();
// Security token used to disable the security manager. Only objects that have a reference to it are allowed to disable it.
Object credential = new Object();
RenderLogger logger = new RenderLogger("theme_editor", module, credential);
final ActionBarCallback actionBarCallback = new ActionBarCallback();
// TODO: Remove LayoutlibCallback dependency.
//noinspection ConstantConditions
final LayoutlibCallbackImpl layoutlibCallback = new LayoutlibCallbackImpl(null, layoutLib, appResources, module, facet, logger, credential, null) {
@Override
public ActionBarCallback getActionBarCallback() {
return actionBarCallback;
}
};
// Load the local project R identifiers.
boolean loadRResult = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
// half way.
if (module.isDisposed()) {
return false;
}
layoutlibCallback.loadAndParseRClass();
return true;
}
});
if (!loadRResult) {
throw new AlreadyDisposedException("Module was already disposed");
}
IAndroidTarget target = configuration.getTarget();
if (target == null) {
throw new InitializationException("Unable to get IAndroidTarget");
}
Device device = configuration.getDevice();
assert device != null;
HardwareConfigHelper hardwareConfigHelper = new HardwareConfigHelper(device);
DynamicHardwareConfig hardwareConfig = new DynamicHardwareConfig(hardwareConfigHelper.getConfig());
List<ResourceValue> resourceLookupChain = new ArrayList<ResourceValue>();
ResourceResolver resourceResolver = ResourceResolver.copy(configuration.getResourceResolver());
assert resourceResolver != null;
// Create a resource resolver that will save the lookups on the passed List<>
ResourceResolver recordingResourceResolver = resourceResolver.createRecorder(resourceLookupChain);
final SessionParams params = new SessionParams(parser, renderingMode, module, hardwareConfig, recordingResourceResolver, layoutlibCallback, moduleInfo.getMinSdkVersion().getApiLevel(), moduleInfo.getTargetSdkVersion().getApiLevel(), logger, target instanceof CompatibilityRenderTarget ? target.getVersion().getApiLevel() : 0);
params.setForceNoDecor();
params.setAssetRepository(new AssetRepositoryImpl(facet));
// The App Label needs to be not null
params.setAppLabel("");
if (backgroundColor != null) {
params.setOverrideBgColor(backgroundColor.getRGB());
}
RenderSecurityManager mySecurityManager = useSecurityManager ? RenderSecurityManagerFactory.create(module, platform) : null;
return new GraphicsLayoutRenderer(layoutLib, params, mySecurityManager, hardwareConfig, resourceLookupChain, credential);
}
use of com.android.sdklib.IAndroidTarget 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 com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidModuleConverter1 method process.
@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
assert confElement != null;
Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
if (platformName == null)
return;
removeOldDependencies(moduleSettings, platformName);
confElement.removeContent(platformNameElement);
Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName);
if (androidLibrary != null) {
AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null);
if (androidPlatform != null) {
IAndroidTarget target = androidPlatform.getTarget();
Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
if (androidSdk == null) {
androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
if (androidSdk != null) {
final SdkModificator modificator = androidSdk.getSdkModificator();
for (OrderRootType type : OrderRootType.getAllTypes()) {
for (VirtualFile root : androidLibrary.getFiles(type)) {
modificator.addRoot(root, type);
}
}
modificator.commitChanges();
}
}
if (androidSdk != null) {
addNewDependency(moduleSettings, androidSdk.getName());
}
}
}
}
Aggregations