use of com.android.sdklib.AndroidVersion in project kotlin by JetBrains.
the class SupportAnnotationDetector method getPermissions.
private PermissionHolder getPermissions(@NonNull JavaContext context) {
if (mPermissions == null) {
Set<String> permissions = Sets.newHashSetWithExpectedSize(30);
Set<String> revocable = Sets.newHashSetWithExpectedSize(4);
LintClient client = context.getClient();
// Gather permissions from all projects that contribute to the
// main project.
Project mainProject = context.getMainProject();
for (File manifest : mainProject.getManifestFiles()) {
addPermissions(client, permissions, revocable, manifest);
}
for (Project library : mainProject.getAllLibraries()) {
for (File manifest : library.getManifestFiles()) {
addPermissions(client, permissions, revocable, manifest);
}
}
AndroidVersion minSdkVersion = mainProject.getMinSdkVersion();
AndroidVersion targetSdkVersion = mainProject.getTargetSdkVersion();
mPermissions = new SetPermissionLookup(permissions, revocable, minSdkVersion, targetSdkVersion);
}
return mPermissions;
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class InstantRunBuilder method computeBuildCause.
@NotNull
private BuildCause computeBuildCause(@Nullable IDevice device) {
if (device == null) {
// i.e. emulator is still launching..
return BuildCause.NO_DEVICE;
}
if (myRunContext.isCleanRerun()) {
return BuildCause.USER_REQUESTED_CLEAN_BUILD;
}
// We assume that the deployment happens to the default user, and in here, we check whether it is still installed for the default user
// (Note: this could be done in a better way if we knew the user for whom the installation actually took place).
int defaultUserId = 0;
if (!isAppInstalledForUser(device, myInstantRunContext.getApplicationId(), defaultUserId)) {
return BuildCause.APP_NOT_INSTALLED;
}
if (!buildTimestampsMatch(device, defaultUserId)) {
return BuildCause.MISMATCHING_TIMESTAMPS;
}
AndroidVersion deviceVersion = device.getVersion();
if (!InstantRunManager.isInstantRunCapableDeviceVersion(deviceVersion)) {
return BuildCause.API_TOO_LOW_FOR_INSTANT_RUN;
}
if (!InstantRunManager.hasLocalCacheOfDeviceData(device, myInstantRunContext)) {
return BuildCause.FIRST_INSTALLATION_TO_DEVICE;
}
// manifest file or a resource referenced from the manifest has changed since the last build.
if (ApplicationManager.getApplication() != null) {
// guard against invoking this in unit tests
GradleBuildInvoker.saveAllFilesSafely();
}
if (manifestResourceChanged(device)) {
return BuildCause.MANIFEST_RESOURCE_CHANGED;
}
if (!isAppRunning(device)) {
// freeze-swap scenario
if (!deviceVersion.isGreaterOrEqualThan(21)) {
// don't support cold swap on API < 21
return BuildCause.FREEZE_SWAP_REQUIRES_API21;
}
}
if (myRunContext.isForceColdswap()) {
return myRunContext.couldHaveInvokedHotswap() ? BuildCause.USER_CHOSE_TO_COLDSWAP : BuildCause.USER_REQUESTED_COLDSWAP;
}
if (!isAppRunning(device)) {
return BuildCause.APP_NOT_RUNNING;
}
if (device.supportsFeature(IDevice.HardwareFeature.TV) || // so look for the Android TV SDK model name specifically until these images are obsolete
StringUtil.notNullize(device.getProperty(IDevice.PROP_DEVICE_MODEL)).contains("sdk_google_atv_")) {
// such as an orientation change never happen on Android TV.
return BuildCause.ANDROID_TV_UNSUPPORTED;
}
if (myInstantRunContext.usesMultipleProcesses()) {
return BuildCause.APP_USES_MULTIPLE_PROCESSES;
}
return BuildCause.INCREMENTAL_BUILD;
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class SdksCleanupStep method reinstallMissingPlatforms.
private void reinstallMissingPlatforms(@NotNull Collection<Sdk> invalidAndroidSdks, @NotNull Project project) {
List<AndroidVersion> versionsToInstall = Lists.newArrayList();
List<String> missingPlatforms = Lists.newArrayList();
for (Sdk sdk : invalidAndroidSdks) {
AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
if (additionalData != null) {
String platform = additionalData.getBuildTargetHashString();
if (platform != null) {
missingPlatforms.add("'" + platform + "'");
AndroidVersion version = AndroidTargetHash.getPlatformVersion(platform);
if (version != null) {
versionsToInstall.add(version);
}
}
}
}
if (!versionsToInstall.isEmpty()) {
String text = "Missing Android platform(s) detected: " + Joiner.on(", ").join(missingPlatforms);
SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
msg.add(new InstallPlatformHyperlink(versionsToInstall));
SyncMessages.getInstance(project).report(msg);
}
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class EmulatorTargetConfigurable method getAvdCompatibilityWarning.
@Nullable
private String getAvdCompatibilityWarning() {
IdDisplay selectedItem = (IdDisplay) myAvdCombo.getComboBox().getSelectedItem();
if (selectedItem != null) {
final String selectedAvdName = selectedItem.getId();
final Module module = myContext.getModule();
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
final AvdManager avdManager = facet.getAvdManagerSilently();
if (avdManager == null) {
return null;
}
final AvdInfo avd = avdManager.getAvd(selectedAvdName, false);
if (avd == null || avd.getSystemImage() == null) {
return null;
}
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
return null;
}
AndroidVersion minSdk = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
LaunchCompatibility compatibility = LaunchCompatibility.canRunOnAvd(minSdk, platform.getTarget(), avd.getSystemImage());
if (compatibility.isCompatible() == ThreeState.NO) {
// todo: provide info about current module configuration
return String.format("'%1$s' may be incompatible with your configuration (%2$s)", selectedAvdName, StringUtil.notNullize(compatibility.getReason()));
}
}
return null;
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class LaunchCompatibility method canRunOnDevice.
/**
* Returns whether an application with the given requirements can be run on the given device.
*
* @param minSdkVersion minSdkVersion specified by the application
* @param projectTarget android target corresponding to the targetSdkVersion
* @param requiredFeatures required list of hardware features
* @param device the device to check compatibility against
* @return a {@link ThreeState} indicating whether the application can be run on the device, and a reason if it isn't
* compatible.
*/
@NotNull
public static LaunchCompatibility canRunOnDevice(@NotNull AndroidVersion minSdkVersion, @NotNull IAndroidTarget projectTarget, @NotNull EnumSet<IDevice.HardwareFeature> requiredFeatures, @Nullable Set<String> supportedAbis, @NotNull AndroidDevice device) {
// check if the device has the required minApi
// note that in cases where targetSdk is a preview platform, gradle sets minsdk to be the same as targetsdk,
// so as to only allow running on those systems
AndroidVersion deviceVersion = device.getVersion();
if (!deviceVersion.equals(AndroidVersion.DEFAULT) && !deviceVersion.canRun(minSdkVersion)) {
String reason = String.format("minSdk(%1$s) %3$s deviceSdk(%2$s)", minSdkVersion, deviceVersion, minSdkVersion.getCodename() == null ? ">" : "!=");
return new LaunchCompatibility(ThreeState.NO, reason);
}
// check if the device provides the required features
for (IDevice.HardwareFeature feature : requiredFeatures) {
if (!device.supportsFeature(feature)) {
return new LaunchCompatibility(ThreeState.NO, "missing feature: " + feature);
}
}
// non-watch apks to be installed on it.
if (device.supportsFeature(IDevice.HardwareFeature.WATCH)) {
if (!requiredFeatures.contains(IDevice.HardwareFeature.WATCH)) {
return new LaunchCompatibility(ThreeState.NO, "missing uses-feature watch, non-watch apks cannot be launched on a watch");
}
}
// Verify that the device ABI matches one of the target ABIs for JNI apps.
if (supportedAbis != null) {
Set<String> deviceAbis = Sets.newLinkedHashSet();
for (Abi abi : device.getAbis()) {
deviceAbis.add(abi.toString());
}
if (!supportedAbis.isEmpty() && Sets.intersection(supportedAbis, deviceAbis).isEmpty()) {
return new LaunchCompatibility(ThreeState.NO, "Device supports " + Joiner.on(", ").join(deviceAbis) + ", but APK only supports " + Joiner.on(", ").join(supportedAbis));
}
}
// we are done with checks for platform targets
if (projectTarget.isPlatform()) {
return YES;
}
// Add-ons specify a list of libraries. We need to check that the required libraries are available on the device.
// See AddOnTarget#canRunOn
List<IAndroidTarget.OptionalLibrary> additionalLibs = projectTarget.getAdditionalLibraries();
if (additionalLibs.isEmpty()) {
return YES;
}
String targetName = projectTarget.getName();
if (GOOGLE_APIS_TARGET_NAME.equals(targetName)) {
// We'll assume that Google APIs are available on all devices.
return YES;
} else {
// Unsure because we don't have an easy way of determining whether those libraries are on a device
return new LaunchCompatibility(ThreeState.UNSURE, "unsure if device supports addon: " + targetName);
}
}
Aggregations