use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class RenderService method getPlatform.
@Nullable
private static AndroidPlatform getPlatform(@NotNull final Module module, @Nullable RenderLogger logger) {
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform == null && logger != null) {
if (!AndroidMavenUtil.isMavenizedModule(module)) {
RenderProblem.Html message = RenderProblem.create(ERROR);
logger.addMessage(message);
message.getHtmlBuilder().addLink("No Android SDK found. Please ", "configure", " an Android SDK.", logger.getLinkManager().createRunnableLink(() -> {
Project project = module.getProject();
ProjectSettingsService service = ProjectSettingsService.getInstance(project);
if (AndroidProjectInfo.getInstance(project).requiresAndroidModel() && service instanceof AndroidProjectSettingsService) {
((AndroidProjectSettingsService) service).openSdkSettings();
return;
}
AndroidSdkUtils.openModuleDependenciesConfigurable(module);
}));
} else {
String message = AndroidBundle.message("android.maven.cannot.parse.android.sdk.error", module.getName());
logger.addMessage(RenderProblem.createPlain(ERROR, message));
}
}
return platform;
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class RenderService method createTask.
/**
* Creates a new {@link RenderService} associated with the given editor.
*
* @return a {@link RenderService} which can perform rendering services
*/
@Nullable
public RenderTask createTask(@Nullable final PsiFile psiFile, @NotNull final Configuration configuration, @NotNull final RenderLogger logger, @Nullable final EditorDesignSurface surface) {
Module module = myFacet.getModule();
final Project project = module.getProject();
AndroidPlatform platform = getPlatform(module, logger);
if (platform == null) {
return null;
}
IAndroidTarget target = configuration.getTarget();
if (target == null) {
logger.addMessage(RenderProblem.createPlain(ERROR, "No render target was chosen"));
return null;
}
warnIfObsoleteLayoutLib(module, logger, surface, target);
LayoutLibrary layoutLib;
try {
layoutLib = platform.getSdkData().getTargetData(target).getLayoutLibrary(project);
if (layoutLib == null) {
String message = AndroidBundle.message("android.layout.preview.cannot.load.library.error");
logger.addMessage(RenderProblem.createPlain(ERROR, message));
return null;
}
} catch (UnsupportedJavaRuntimeException e) {
RenderProblem.Html javaVersionProblem = RenderProblem.create(ERROR);
javaVersionProblem.getHtmlBuilder().add(e.getPresentableMessage()).newline().addLink("Install a supported JDK", JDK_INSTALL_URL);
logger.addMessage(javaVersionProblem);
return null;
} catch (RenderingException e) {
String message = e.getPresentableMessage();
message = message != null ? message : AndroidBundle.message("android.layout.preview.default.error.message");
logger.addMessage(RenderProblem.createPlain(ERROR, message, module.getProject(), logger.getLinkManager(), e));
return null;
} catch (IOException e) {
final String message = e.getMessage();
logger.error(null, "I/O error: " + (message != null ? ": " + message : ""), e);
return null;
}
if (psiFile != null && TAG_PREFERENCE_SCREEN.equals(AndroidPsiUtils.getRootTagName(psiFile)) && !layoutLib.supports(Features.PREFERENCES_RENDERING)) {
// This means that user is using an outdated version of layoutlib. A warning to update has already been
// presented in warnIfObsoleteLayoutLib(). Just log a plain message asking users to update.
logger.addMessage(RenderProblem.createPlain(ERROR, "This version of the rendering library does not support rendering Preferences. " + "Update it using the SDK Manager"));
return null;
}
Device device = configuration.getDevice();
if (device == null) {
logger.addMessage(RenderProblem.createPlain(ERROR, "No device selected"));
return null;
}
try {
RenderTask task = new RenderTask(this, configuration, logger, layoutLib, device, myCredential, CrashReporter.getInstance());
if (psiFile != null) {
task.setPsiFile(psiFile);
}
task.setDesignSurface(surface);
return task;
} catch (IncorrectOperationException | AssertionError e) {
// We can get this exception if the module/project is closed while we are updating the model. Ignore it.
assert myFacet.isDisposed();
}
return null;
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class RenderErrorContributor method reportTagResourceFormat.
private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
Object clientData = message.getClientData();
if (!(clientData instanceof String[])) {
return;
}
String[] strings = (String[]) clientData;
if (strings.length != 2) {
return;
}
RenderTask renderTask = result.getRenderTask();
if (renderTask == null) {
return;
}
IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
if (target == null) {
return;
}
AndroidPlatform platform = renderTask.getPlatform();
if (platform == null) {
return;
}
AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
final String attributeName = strings[0];
final String currentValue = strings[1];
if (definitionLookup == null) {
return;
}
AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
if (definition == null) {
return;
}
Set<AttributeFormat> formats = definition.getFormats();
if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
String[] values = definition.getValues();
if (values.length > 0) {
HtmlBuilder builder = new HtmlBuilder();
builder.add("Change ").add(currentValue).add(" to: ");
boolean first = true;
for (String value : values) {
if (first) {
first = false;
} else {
builder.add(", ");
}
builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
}
addRefreshAction(builder);
addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
}
}
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidPrecompileTask method prepareForCompilation.
private static boolean prepareForCompilation(CompileContext context) {
final Project project = context.getProject();
if (!checkArtifacts(context)) {
return false;
}
checkAndroidDependencies(context);
ExcludesConfiguration configuration = CompilerConfiguration.getInstance(project).getExcludedEntriesConfiguration();
Set<ExcludeEntryDescription> addedEntries = new HashSet<>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
continue;
}
if (context.isRebuild()) {
clearResCache(facet, context);
}
final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
final int platformToolsRevision = platform != null ? platform.getSdkData().getPlatformToolsRevision() : -1;
LOG.debug("Platform-tools revision for module " + module.getName() + " is " + platformToolsRevision);
if (!facet.isAppProject()) {
if (platformToolsRevision >= 0 && platformToolsRevision <= 7) {
LOG.debug("Excluded sources of module " + module.getName());
excludeAllSourceRoots(module, configuration, addedEntries);
} else {
// todo: support this by project converter to use on compile-server
unexcludeAllSourceRoots(facet, configuration);
}
}
}
if (addedEntries.size() > 0) {
LOG.debug("Files excluded by Android: " + addedEntries.size());
project.getMessageBus().connect().subscribe(CompilerTopics.COMPILATION_STATUS, new MyCompilationStatusListener(project, addedEntries));
}
return true;
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidCompileUtil method isExcludedFromCompilation.
public static boolean isExcludedFromCompilation(VirtualFile child, @Nullable Project project) {
final CompilerManager compilerManager = project != null ? CompilerManager.getInstance(project) : null;
if (compilerManager == null) {
return false;
}
if (!compilerManager.isExcludedFromCompilation(child)) {
return false;
}
final Module module = ModuleUtil.findModuleForFile(child, project);
if (module == null) {
return true;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.isAppProject()) {
return true;
}
final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
return true;
}
// we exclude sources of library modules automatically for tools r7 or previous
return platform.getSdkData().getPlatformToolsRevision() > 7;
}
Aggregations