use of com.android.sdklib.BuildToolInfo 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 com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class NewModuleWizardState method putSdkDependentParams.
public void putSdkDependentParams() {
final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(getClass()), false);
if (buildTool != null) {
// If buildTool is null, the template will use buildApi instead, which might be good enough.
put(ATTR_BUILD_TOOLS_VERSION, buildTool.getRevision().toString());
}
File location = sdkHandler.getLocation();
if (location != null) {
// Gradle expects a platform-neutral path
put(ATTR_SDK_DIR, FileUtil.toSystemIndependentName(location.getPath()));
}
}
use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class InstantRunConfigurable method updateProjectToInstantRunTools.
/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
// Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
}
// Update plugin version
AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
// Should be at least 23.0.2
String buildToolsVersion = "23.0.2";
AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
if (latestBuildTool != null) {
Revision revision = latestBuildTool.getRevision();
if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
buildToolsVersion = revision.toShortString();
}
}
// Also update build files to set build tools version 23.0.2
GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
// Also update Gradle wrapper version
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
}
// Request a sync
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
return true;
} else {
return false;
}
}
use of com.android.sdklib.BuildToolInfo in project android by JetBrains.
the class TemplateTest method createNewProjectState.
private static NewProjectWizardState createNewProjectState(boolean createWithProject, AndroidSdkData sdkData) {
NewProjectWizardState values = new NewProjectWizardState();
assertNotNull(values);
Template.convertApisToInt(values.getParameters());
values.put(ATTR_CREATE_ACTIVITY, createWithProject);
values.put(ATTR_GRADLE_VERSION, GRADLE_LATEST_VERSION);
values.put(ATTR_GRADLE_PLUGIN_VERSION, GRADLE_PLUGIN_RECOMMENDED_VERSION);
values.put(ATTR_MODULE_NAME, "TestModule");
values.put(ATTR_PACKAGE_NAME, "test.pkg");
// TODO: Test the icon generator too
values.put(ATTR_CREATE_ICONS, false);
BuildToolInfo buildTool = sdkData.getLatestBuildTool();
if (buildTool != null) {
values.put(ATTR_BUILD_TOOLS_VERSION, buildTool.getRevision().toString());
}
return values;
}
use of com.android.sdklib.BuildToolInfo in project kotlin by JetBrains.
the class ApiDetector method visitAttribute.
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
if (mApiDatabase == null) {
return;
}
int attributeApiLevel = -1;
if (ANDROID_URI.equals(attribute.getNamespaceURI())) {
String name = attribute.getLocalName();
if (!(name.equals(ATTR_LAYOUT_WIDTH) && !(name.equals(ATTR_LAYOUT_HEIGHT)) && !(name.equals(ATTR_ID)))) {
//$NON-NLS-1$
String owner = "android/R$attr";
attributeApiLevel = mApiDatabase.getFieldVersion(owner, name);
int minSdk = getMinSdk(context);
if (attributeApiLevel > minSdk && attributeApiLevel > context.getFolderVersion() && attributeApiLevel > getLocalMinSdk(attribute.getOwnerElement()) && !isBenignUnusedAttribute(name) && !isAlreadyWarnedDrawableFile(context, attribute, attributeApiLevel)) {
if (RtlDetector.isRtlAttributeName(name) || ATTR_SUPPORTS_RTL.equals(name)) {
// the resources differently.
if (name.equals(ATTR_PADDING_START)) {
BuildToolInfo buildToolInfo = context.getProject().getBuildTools();
Revision buildTools = buildToolInfo != null ? buildToolInfo.getRevision() : null;
boolean isOldBuildTools = buildTools != null && (buildTools.getMajor() < 23 || buildTools.getMajor() == 23 && buildTools.getMinor() == 0 && buildTools.getMicro() == 0);
if ((buildTools == null || isOldBuildTools) && viewMayExtendTextView(attribute.getOwnerElement())) {
Location location = context.getLocation(attribute);
String message = String.format("Attribute `%1$s` referenced here can result in a crash on " + "some specific devices older than API %2$d " + "(current min is %3$d)", attribute.getLocalName(), attributeApiLevel, minSdk);
//noinspection VariableNotUsedInsideIf
if (buildTools != null) {
message = String.format("Upgrade `buildToolsVersion` from " + "`%1$s` to at least `23.0.1`; if not, ", buildTools.toShortString()) + Character.toLowerCase(message.charAt(0)) + message.substring(1);
}
context.report(UNSUPPORTED, attribute, location, message);
}
}
} else {
Location location = context.getLocation(attribute);
String message = String.format("Attribute `%1$s` is only used in API level %2$d and higher " + "(current min is %3$d)", attribute.getLocalName(), attributeApiLevel, minSdk);
context.report(UNUSED, attribute, location, message);
}
}
}
// since this will work just fine. See issue 67440 for more.
if (name.equals("divider")) {
return;
}
}
String value = attribute.getValue();
String owner = null;
String name = null;
String prefix;
if (value.startsWith(ANDROID_PREFIX)) {
prefix = ANDROID_PREFIX;
} else if (value.startsWith(ANDROID_THEME_PREFIX)) {
prefix = ANDROID_THEME_PREFIX;
if (context.getResourceFolderType() == ResourceFolderType.DRAWABLE) {
int api = 21;
int minSdk = getMinSdk(context);
if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(attribute.getOwnerElement())) {
Location location = context.getLocation(attribute);
String message;
message = String.format("Using theme references in XML drawables requires API level %1$d " + "(current min is %2$d)", api, minSdk);
context.report(UNSUPPORTED, attribute, location, message);
// API level 11
return;
}
}
} else if (value.startsWith(PREFIX_ANDROID) && ATTR_NAME.equals(attribute.getName()) && TAG_ITEM.equals(attribute.getOwnerElement().getTagName()) && attribute.getOwnerElement().getParentNode() != null && TAG_STYLE.equals(attribute.getOwnerElement().getParentNode().getNodeName())) {
//$NON-NLS-1$
owner = "android/R$attr";
name = value.substring(PREFIX_ANDROID.length());
prefix = null;
} else if (value.startsWith(PREFIX_ANDROID) && ATTR_PARENT.equals(attribute.getName()) && TAG_STYLE.equals(attribute.getOwnerElement().getTagName())) {
//$NON-NLS-1$
owner = "android/R$style";
name = getResourceFieldName(value.substring(PREFIX_ANDROID.length()));
prefix = null;
} else {
return;
}
if (owner == null) {
// Convert @android:type/foo into android/R$type and "foo"
int index = value.indexOf('/', prefix.length());
if (index != -1) {
owner = //$NON-NLS-1$
"android/R$" + value.substring(prefix.length(), index);
name = getResourceFieldName(value.substring(index + 1));
} else if (value.startsWith(ANDROID_THEME_PREFIX)) {
//$NON-NLS-1$
owner = "android/R$attr";
name = value.substring(ANDROID_THEME_PREFIX.length());
} else {
return;
}
}
int api = mApiDatabase.getFieldVersion(owner, name);
int minSdk = getMinSdk(context);
if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(attribute.getOwnerElement())) {
// used only for designtime previews
if (TOOLS_URI.equals(attribute.getNamespaceURI())) {
return;
}
//noinspection StatementWithEmptyBody
if (attributeApiLevel >= api) {
// The attribute will only be *read* on platforms >= attributeApiLevel.
// If this isn't lower than the attribute reference's API level, it
// won't be a problem
} else if (attributeApiLevel > minSdk) {
String attributeName = attribute.getLocalName();
Location location = context.getLocation(attribute);
String message = String.format("`%1$s` requires API level %2$d (current min is %3$d), but note " + "that attribute `%4$s` is only used in API level %5$d " + "and higher", name, api, minSdk, attributeName, attributeApiLevel);
context.report(UNSUPPORTED, attribute, location, message);
} else {
Location location = context.getLocation(attribute);
String message = String.format("`%1$s` requires API level %2$d (current min is %3$d)", value, api, minSdk);
context.report(UNSUPPORTED, attribute, location, message);
}
}
}
Aggregations