Search in sources :

Example 21 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class InstantRunBuilderTest method fullBuildIfManifestResourceChanged.

@Test
public void fullBuildIfManifestResourceChanged() throws Exception {
    myDumpsysPackageOutput = DUMPSYS_PACKAGE_EXISTS;
    myDeviceBuildTimetamp = "100";
    when(myDevice.getVersion()).thenReturn(new AndroidVersion(23, null));
    myInstalledPatchCache.setInstalledManifestResourcesHash(myDevice, APPLICATION_ID, HashCode.fromInt(1));
    when(myInstantRunContext.getManifestResourcesHash()).thenReturn(HashCode.fromInt(2));
    myBuilder.build(myTaskRunner, Collections.emptyList());
    assertEquals("gradlew -Pandroid.optional.compilation=INSTANT_DEV,FULL_APK -Pandroid.injected.coldswap.mode=MULTIAPK :app:assemble", myTaskRunner.getBuilds());
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) Test(org.junit.Test)

Example 22 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class InstantRunBuilderTest method coldSwapBuildIfAppNotRunning.

@Test
public void coldSwapBuildIfAppNotRunning() throws Exception {
    myDumpsysPackageOutput = DUMPSYS_PACKAGE_EXISTS;
    myDeviceBuildTimetamp = "100";
    myAppInForeground = false;
    myRunConfigContext.setSameExecutorAsPreviousSession(true);
    when(myDevice.getVersion()).thenReturn(new AndroidVersion(23, null));
    setUpDeviceForHotSwap();
    myBuilder.build(myTaskRunner, Collections.emptyList());
    assertEquals("gradlew -Pandroid.optional.compilation=INSTANT_DEV,RESTART_ONLY -Pandroid.injected.coldswap.mode=MULTIAPK :app:assemble", myTaskRunner.getBuilds());
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) Test(org.junit.Test)

Example 23 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class SystemImageList method installForDevice.

private void installForDevice() {
    int apiLevel = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
    List<String> requestedPackages = Lists.newArrayListWithCapacity(3);
    requestedPackages.add(DetailsTypes.getSysImgPath(null, new AndroidVersion(apiLevel, null), DEFAULT_TAG, Abi.X86.toString()));
    requestedPackages.add(DetailsTypes.getSysImgPath(null, new AndroidVersion(apiLevel, null), WEAR_TAG, Abi.X86.toString()));
    requestedPackages.add(DetailsTypes.getSysImgPath(null, new AndroidVersion(apiLevel, null), TV_TAG, Abi.X86.toString()));
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(this, requestedPackages, false);
    if (dialog != null) {
        dialog.show();
        myModel.refreshImages(true);
    }
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 24 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class MakeBeforeRunTaskProvider method getDeviceSpecificArguments.

@NotNull
public static List<String> getDeviceSpecificArguments(@NotNull List<AndroidDevice> devices) {
    if (devices.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> properties = new ArrayList<>(2);
    // Find the minimum value of the build API level and pass it to Gradle as a property
    AndroidVersion minVersion = devices.get(0).getVersion();
    for (int i = 1; i < devices.size(); i++) {
        AndroidDevice androidDevice = devices.get(i);
        if (androidDevice.getVersion().compareTo(minVersion) < 0) {
            minVersion = androidDevice.getVersion();
        }
    }
    properties.add(AndroidGradleSettings.createProjectProperty(PROPERTY_BUILD_API, Integer.toString(minVersion.getFeatureLevel())));
    // If we are building for only one device, pass the density and the ABI
    if (devices.size() == 1) {
        AndroidDevice device = devices.get(0);
        Density density = Density.getEnum(device.getDensity());
        if (density != null) {
            properties.add(AndroidGradleSettings.createProjectProperty(PROPERTY_BUILD_DENSITY, density.getResourceValue()));
        }
        // Note: the abis are returned in their preferred order which should be maintained while passing it on to Gradle.
        List<String> abis = device.getAbis().stream().map(Abi::toString).collect(Collectors.toList());
        if (!abis.isEmpty()) {
            properties.add(AndroidGradleSettings.createProjectProperty(PROPERTY_BUILD_ABI, Joiner.on(',').join(abis)));
        }
    }
    return properties;
}
Also used : ArrayList(java.util.ArrayList) AndroidVersion(com.android.sdklib.AndroidVersion) Density(com.android.resources.Density) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class ConfigureTemplateParametersStep method onProceeding.

/**
   * When finished with this step, calculate and install a bunch of values that will be used in our
   * template's <a href="http://freemarker.incubator.apache.org/docs/dgui_quickstart_basics.html">data model.</a>
   */
@Override
protected void onProceeding() {
    // canGoForward guarantees this optional value is present
    AndroidSourceSet sourceSet = getModel().getSourceSet().get();
    AndroidProjectPaths paths = sourceSet.getPaths();
    File moduleRoot = paths.getModuleRoot();
    if (moduleRoot == null) {
        getLog().error(String.format("%s failure: can't create files because module root is not found. Please report this error.", getTitle()));
        return;
    }
    // Some parameter values should be saved for later runs through this wizard, so do that first.
    for (RowEntry rowEntry : myParameterRows.values()) {
        rowEntry.accept();
    }
    // Prepare the template data-model, starting from scratch and filling in all values we know
    Map<String, Object> templateValues = getModel().getTemplateValues();
    templateValues.clear();
    for (Parameter parameter : myParameterRows.keySet()) {
        ObservableValue<?> property = myParameterRows.get(parameter).getProperty();
        if (property != null) {
            templateValues.put(parameter.id, property.get());
        }
    }
    templateValues.put(ATTR_PACKAGE_NAME, myPackageName.get());
    templateValues.put(ATTR_SOURCE_PROVIDER_NAME, sourceSet.getName());
    // Android Modules are called Gradle Projects
    templateValues.put(ATTR_IS_NEW_PROJECT, isNewModule());
    if (isNewModule()) {
        templateValues.put(ATTR_IS_LAUNCHER, true);
    }
    try {
        File sha1File = myFacet == null ? getOrCreateDefaultDebugKeystore() : getDebugKeystore(myFacet);
        templateValues.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(sha1File));
    } catch (Exception e) {
        getLog().info("Could not compute SHA1 hash of debug keystore.", e);
        templateValues.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
    }
    if (myFacet == null) {
        // If we don't have an AndroidFacet, we must have the Android Sdk info
        AndroidVersionsInfo.VersionItem buildVersion = getModel().androidSdkInfo().getValue();
        templateValues.put(ATTR_MIN_API_LEVEL, buildVersion.getApiLevel());
        templateValues.put(ATTR_MIN_API, buildVersion.getApiLevelStr());
        templateValues.put(ATTR_BUILD_API, buildVersion.getBuildApiLevel());
        templateValues.put(ATTR_BUILD_API_STRING, buildVersion.getBuildApiLevelStr());
        templateValues.put(ATTR_TARGET_API, buildVersion.getTargetApiLevel());
        templateValues.put(ATTR_TARGET_API_STRING, buildVersion.getTargetApiLevelStr());
    } else {
        AndroidPlatform platform = AndroidPlatform.getInstance(myFacet.getModule());
        if (platform != null) {
            templateValues.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
            templateValues.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
        }
        AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(myFacet);
        AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
        String minSdkName = minSdkVersion.getApiString();
        templateValues.put(ATTR_MIN_API, minSdkName);
        templateValues.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
        templateValues.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
        templateValues.put(ATTR_IS_LIBRARY_MODULE, myFacet.isLibraryProject());
        // Register application-wide settings
        String applicationPackage = AndroidPackageUtils.getPackageForApplication(myFacet);
        if (!myPackageName.get().equals(applicationPackage)) {
            templateValues.put(ATTR_APPLICATION_PACKAGE, AndroidPackageUtils.getPackageForApplication(myFacet));
        }
    }
    // Register the resource directories associated with the active source provider
    templateValues.put(ATTR_PROJECT_OUT, FileUtil.toSystemIndependentName(moduleRoot.getAbsolutePath()));
    String packageAsDir = myPackageName.get().replace('.', File.separatorChar);
    File srcDir = paths.getSrcDirectory();
    if (srcDir != null) {
        srcDir = new File(srcDir, packageAsDir);
        templateValues.put(ATTR_SRC_DIR, getRelativePath(moduleRoot, srcDir));
        templateValues.put(ATTR_SRC_OUT, FileUtil.toSystemIndependentName(srcDir.getAbsolutePath()));
    }
    File testDir = paths.getTestDirectory();
    if (testDir != null) {
        testDir = new File(testDir, packageAsDir);
        templateValues.put(ATTR_TEST_DIR, getRelativePath(moduleRoot, testDir));
        templateValues.put(ATTR_TEST_OUT, FileUtil.toSystemIndependentName(testDir.getAbsolutePath()));
    }
    File resDir = paths.getResDirectory();
    if (resDir != null) {
        templateValues.put(ATTR_RES_DIR, getRelativePath(moduleRoot, resDir));
        templateValues.put(ATTR_RES_OUT, FileUtil.toSystemIndependentName(resDir.getPath()));
    }
    File manifestDir = paths.getManifestDirectory();
    if (manifestDir != null) {
        templateValues.put(ATTR_MANIFEST_DIR, getRelativePath(moduleRoot, manifestDir));
        templateValues.put(ATTR_MANIFEST_OUT, FileUtil.toSystemIndependentName(manifestDir.getPath()));
    }
    File aidlDir = paths.getAidlDirectory();
    if (aidlDir != null) {
        templateValues.put(ATTR_AIDL_DIR, getRelativePath(moduleRoot, aidlDir));
        templateValues.put(ATTR_AIDL_OUT, FileUtil.toSystemIndependentName(aidlDir.getPath()));
    }
    templateValues.put(PROJECT_LOCATION_ID, moduleRoot.getParent());
    // We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
    // name as its containing project.
    String moduleName = moduleRoot.getName();
    templateValues.put(ATTR_MODULE_NAME, moduleName);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) AndroidVersionsInfo(com.android.tools.idea.npw.platform.AndroidVersionsInfo) File(java.io.File) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) AndroidProjectPaths(com.android.tools.idea.npw.project.AndroidProjectPaths)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3