use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class ExportSignedPackageWizard method createAndAlignApk.
private void createAndAlignApk(final String apkPath) {
AndroidPlatform platform = getFacet().getConfiguration().getAndroidPlatform();
assert platform != null;
String sdkPath = platform.getSdkData().getLocation().getPath();
String zipAlignPath = AndroidCommonUtils.getZipAlign(sdkPath, platform.getTarget());
File zipalign = new File(zipAlignPath);
if (!zipalign.isFile()) {
BuildToolInfo buildTool = platform.getTarget().getBuildToolInfo();
if (buildTool != null) {
zipAlignPath = buildTool.getPath(BuildToolInfo.PathId.ZIP_ALIGN);
zipalign = new File(zipAlignPath);
}
}
final boolean runZipAlign = zipalign.isFile();
File destFile = null;
try {
destFile = runZipAlign ? FileUtil.createTempFile("android", ".apk") : new File(apkPath);
createApk(destFile);
} catch (Exception e) {
showErrorInDispatchThread(e.getMessage());
}
if (destFile == null) {
return;
}
if (runZipAlign) {
File realDestFile = new File(apkPath);
String message = AndroidCommonUtils.executeZipAlign(zipAlignPath, destFile, realDestFile);
if (message != null) {
showErrorInDispatchThread(message);
return;
}
}
invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
String title = AndroidBundle.message("android.export.package.wizard.title");
Project project = getProject();
File apkFile = new File(apkPath);
VirtualFile vApkFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(apkFile);
if (vApkFile != null) {
vApkFile.refresh(true, false);
}
if (!runZipAlign) {
Messages.showWarningDialog(project, AndroidCommonBundle.message("android.artifact.building.cannot.find.zip.align.error"), title);
}
if (ShowFilePathAction.isSupported()) {
if (Messages.showOkCancelDialog(project, AndroidBundle.message("android.export.package.success.message", apkFile.getName()), title, RevealFileAction.getActionName(), IdeBundle.message("action.close"), Messages.getInformationIcon()) == Messages.OK) {
ShowFilePathAction.openFile(apkFile);
}
} else {
Messages.showInfoMessage(project, AndroidBundle.message("android.export.package.success.message", apkFile), title);
}
}
});
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class ResourceHelper method getCompletionFromTypes.
/**
* Returns the list of all resource names that can be used as a value for one of the {@link ResourceType} in completionTypes,
* optionally sorting/not sorting the results.
*/
@NotNull
public static List<String> getCompletionFromTypes(@NotNull AndroidFacet facet, @NotNull EnumSet<ResourceType> completionTypes, boolean sort) {
EnumSet<ResourceType> types = Sets.newEnumSet(completionTypes, ResourceType.class);
// Use drawables for mipmaps
if (types.contains(ResourceType.MIPMAP)) {
types.add(ResourceType.DRAWABLE);
} else if (types.contains(ResourceType.DRAWABLE)) {
types.add(ResourceType.MIPMAP);
}
boolean completionTypesContainsColor = types.contains(ResourceType.COLOR);
if (types.contains(ResourceType.DRAWABLE)) {
// The Drawable type accepts colors as value but not color state lists.
types.add(ResourceType.COLOR);
}
AppResourceRepository repository = AppResourceRepository.getAppResources(facet, true);
ResourceVisibilityLookup lookup = repository.getResourceVisibility(facet);
AndroidPlatform androidPlatform = AndroidPlatform.getInstance(facet.getModule());
FrameworkResources frameworkResources = null;
if (androidPlatform != null) {
AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(androidPlatform.getTarget());
try {
frameworkResources = targetData.getFrameworkResources(true);
} catch (IOException ignore) {
}
}
List<String> resources = Lists.newArrayListWithCapacity(500);
for (ResourceType type : types) {
// If type == ResourceType.COLOR, we want to include file resources (i.e. color state lists) only in the case where
// color was present in completionTypes, and not if we added it because of the presence of ResourceType.DRAWABLES.
// For any other ResourceType, we always include file resources.
boolean includeFileResources = (type != ResourceType.COLOR) || completionTypesContainsColor;
if (frameworkResources != null) {
addFrameworkItems(resources, type, includeFileResources, frameworkResources);
}
addProjectItems(resources, type, includeFileResources, repository, lookup);
}
if (sort) {
Collections.sort(resources, ResourceHelper::compareResourceReferences);
}
return resources;
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AttachAndroidSdkSourcesNotificationProvider method createNotificationPanel.
@Override
@Nullable
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
if (file.getFileType() != JavaClassFileType.INSTANCE) {
return null;
}
// Locate the java source of the class file, if not found, then it might come from a SDK.
if (JavaEditorFileSwapper.findSourceFile(myProject, file) == null) {
JdkOrderEntry jdkOrderEntry = findAndroidSdkEntryForFile(file);
if (jdkOrderEntry == null) {
return null;
}
Sdk sdk = jdkOrderEntry.getJdk();
String sdkHome = sdk.getHomePath();
if (sdkHome == null) {
return null;
}
if (sdk.getRootProvider().getFiles(OrderRootType.SOURCES).length > 0) {
return null;
}
AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
if (platform == null) {
return null;
}
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText("Sources for '" + jdkOrderEntry.getJdkName() + "' not found.");
panel.createActionLabel("Download", () -> {
List<String> requested = Lists.newArrayList();
requested.add(DetailsTypes.getSourcesPath(platform.getApiVersion()));
ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(myProject, requested);
if (dialog != null && dialog.showAndGet()) {
updateSdkSourceRoot(sdk);
}
});
panel.createActionLabel("Refresh (if already downloaded)", () -> updateSdkSourceRoot(sdk));
return panel;
}
return null;
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AddAndroidActivityPath method init.
@Override
protected void init() {
Module module = getModule();
assert module != null;
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
myState.put(KEY_BUILD_SDK, platform.getTarget().getVersion().getFeatureLevel());
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
myState.put(KEY_MIN_SDK, minSdkVersion);
myState.put(KEY_TARGET_API, moduleInfo.getTargetSdkVersion());
myState.put(KEY_PACKAGE_NAME, getInitialPackageName(module, facet));
myState.put(KEY_OPEN_EDITORS, true);
if (myTemplate == null) {
FormFactor formFactor = getFormFactor(myTargetFolder);
myState.put(FormFactorUtils.getMinApiLevelKey(formFactor), minSdkVersion.getApiLevel());
myState.put(FormFactorUtils.getBuildApiLevelKey(formFactor), moduleInfo.getTargetSdkVersion().getApiLevel());
ActivityGalleryStep galleryStep = new ActivityGalleryStep(formFactor, false, KEY_SELECTED_TEMPLATE, module, myParentDisposable);
addStep(galleryStep);
} else {
TemplateMetadata templateMetadata = TemplateManager.getInstance().getTemplateMetadata(myTemplate);
assert templateMetadata != null;
myState.put(KEY_SELECTED_TEMPLATE, new TemplateEntry(myTemplate, templateMetadata));
}
SourceProvider[] sourceProviders = getSourceProviders(module, myTargetFolder);
boolean isInstantAppModule = facet.getProjectType() == PROJECT_TYPE_ATOM;
myState.put(IS_INSTANT_APP_KEY, isInstantAppModule);
myParameterStep = new TemplateParameterStep2(getFormFactor(myTargetFolder), ImmutableMap.of(), myParentDisposable, KEY_PACKAGE_NAME, sourceProviders, CUSTOMIZE_ACTIVITY_TITLE);
myAssetStudioStep = new IconStep(KEY_SELECTED_TEMPLATE, KEY_SOURCE_PROVIDER, myParentDisposable);
addStep(myParameterStep);
addStep(myAssetStudioStep);
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class LaunchCompatibilityCheckerImpl method create.
public static LaunchCompatibilityChecker create(@NotNull AndroidFacet facet) {
AndroidVersion minSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
throw new IllegalStateException("Android platform not set for module: " + facet.getModule().getName());
}
// Currently, we only look at whether the device supports the watch feature.
// We may not want to search the device for every possible feature, but only a small subset of important
// features, starting with hardware type watch.
EnumSet<IDevice.HardwareFeature> requiredHardwareFeatures;
if (LaunchUtils.isWatchFeatureRequired(facet)) {
requiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
} else {
requiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
}
Set<String> supportedAbis = facet.getAndroidModel() instanceof AndroidModuleModel ? ((AndroidModuleModel) facet.getAndroidModel()).getSelectedVariant().getMainArtifact().getAbiFilters() : null;
return new LaunchCompatibilityCheckerImpl(minSdkVersion, platform.getTarget(), requiredHardwareFeatures, supportedAbis);
}
Aggregations