/** * Return the minSdkVersion for this variant. * * <p>This uses both the value from the manifest (if present), and the override coming from the * flavor(s) (if present). The value of the minSdkVersion will be combined with the value of the * targetSdkVersion. For the details of the overlaying logic check {@link * #getCalculatedApiVersions(ApiVersion, ApiVersion)} method. * * @return the minSdkVersion */ @NonNull public ApiVersion getMinSdkVersion() { if (mTestedConfig != null) { return mTestedConfig.getMinSdkVersion(); } return getApiVersionsNonTestVariant().minSdkVersion; }
/** * Return the targetSdkVersion for this variant. * * This uses both the value from the manifest (if present), and the override coming * from the flavor(s) (if present). The value of the targetSdkVersion will be combined with * the value of the minSdkVersion. For the details of the overlaying logic check * {@link #getCalculatedApiVersions(ApiVersion, ApiVersion)} method. * * @return the targetSdkVersion */ @NonNull public ApiVersion getTargetSdkVersion() { if (mTestedConfig != null) { return mTestedConfig.getTargetSdkVersion(); } return getApiVersionsNonTestVariant().targetSdkVersion; }
/** * Return the minSdkVersion for filtering out resources. * * <p>This is always the minimum SDK version read from the manifest and/or DSL, ignoring the * property passed from the IDE. This way R.java contents don't change depending on the device * selected in the IDE. */ @NonNull public ApiVersion getResourcesMinSdkVersion() { VariantConfiguration testedConfig = getTestedConfig(); if (testedConfig == null) { return super.getApiVersionsNonTestVariant().minSdkVersion; } else if (testedConfig instanceof GradleVariantConfiguration) { return ((GradleVariantConfiguration) testedConfig).getResourcesMinSdkVersion(); } else { return testedConfig.getMinSdkVersion(); } }
@Override public ApiVersions getApiVersionsNonTestVariant() { ApiVersions apiVersions = super.getApiVersionsNonTestVariant(); if (!project.hasProperty(AndroidProject.PROPERTY_BUILD_API) || !getBuildType().isDebuggable()) { return apiVersions; } // Consider runtime API passed from the IDE only if the app is debuggable. Integer targetAPILevel = Integer.parseInt(project.property(AndroidProject.PROPERTY_BUILD_API).toString()); if (targetAPILevel < 23) { // max 100 DEX files in native multidex for L - see http://b.android.com/233093 return apiVersions; } int minVersion = apiVersions.targetSdkVersion.getApiLevel() > 0 ? Integer.min(apiVersions.targetSdkVersion.getApiLevel(), targetAPILevel) : targetAPILevel; return new ApiVersions(new DefaultApiVersion(minVersion), apiVersions.targetSdkVersion); }