use of com.android.builder.model.AndroidArtifact in project kotlin by JetBrains.
the class Project method getApplicableDensities.
/**
* Returns the set of applicable densities for this project. If null, there are no density
* restrictions and all densities apply.
*
* @return the list of specific densities that apply in this project, or null if all densities
* apply
*/
@Nullable
public List<String> getApplicableDensities() {
if (mCachedApplicableDensities == null) {
// ...then we should only enforce hdpi densities, not all these others!
if (isGradleProject() && getGradleProjectModel() != null && getCurrentVariant() != null) {
Set<String> relevantDensities = Sets.newHashSet();
Variant variant = getCurrentVariant();
List<String> variantFlavors = variant.getProductFlavors();
AndroidProject gradleProjectModel = getGradleProjectModel();
addResConfigsFromFlavor(relevantDensities, null, getGradleProjectModel().getDefaultConfig());
for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
}
// Are there any splits that specify densities?
if (relevantDensities.isEmpty()) {
AndroidArtifact mainArtifact = variant.getMainArtifact();
Collection<AndroidArtifactOutput> outputs = mainArtifact.getOutputs();
for (AndroidArtifactOutput output : outputs) {
for (OutputFile file : output.getOutputs()) {
final String DENSITY_NAME = OutputFile.FilterType.DENSITY.name();
if (file.getFilterTypes().contains(DENSITY_NAME)) {
for (FilterData data : file.getFilters()) {
if (DENSITY_NAME.equals(data.getFilterType())) {
relevantDensities.add(data.getIdentifier());
}
}
}
}
}
}
if (!relevantDensities.isEmpty()) {
mCachedApplicableDensities = Lists.newArrayListWithExpectedSize(10);
for (String density : relevantDensities) {
String folder = ResourceFolderType.DRAWABLE.getName() + '-' + density;
mCachedApplicableDensities.add(folder);
}
Collections.sort(mCachedApplicableDensities);
} else {
mCachedApplicableDensities = Collections.emptyList();
}
} else {
mCachedApplicableDensities = Collections.emptyList();
}
}
return mCachedApplicableDensities.isEmpty() ? null : mCachedApplicableDensities;
}
use of com.android.builder.model.AndroidArtifact in project android by JetBrains.
the class AndroidTestRunConfiguration method supportsRunningLibraryProjects.
@Override
protected Pair<Boolean, String> supportsRunningLibraryProjects(@NotNull AndroidFacet facet) {
if (!facet.requiresAndroidModel()) {
// Non Gradle projects always require an application
return Pair.create(Boolean.FALSE, AndroidBundle.message("android.cannot.run.library.project.error"));
}
// TODO: Resolve direct AndroidGradleModel dep (b/22596984)
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel == null) {
return Pair.create(Boolean.FALSE, AndroidBundle.message("android.cannot.run.library.project.error"));
}
// Gradle only supports testing against a single build type (which could be anything, but is "debug" build type by default)
// Currently, the only information the model exports that we can use to detect whether the current build type
// is testable is by looking at the test task name and checking whether it is null.
AndroidArtifact testArtifact = androidModel.getAndroidTestArtifactInSelectedVariant();
String testTask = testArtifact != null ? testArtifact.getAssembleTaskName() : null;
return new Pair<Boolean, String>(testTask != null, AndroidBundle.message("android.cannot.run.library.project.in.this.buildtype"));
}
use of com.android.builder.model.AndroidArtifact in project android by JetBrains.
the class GradleApkProvider method getApks.
@Override
@NotNull
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
if (androidModel == null) {
LOG.warn("Android model is null. Sync might have failed");
return Collections.emptyList();
}
Variant selectedVariant = androidModel.getSelectedVariant();
List<ApkInfo> apkList = Lists.newArrayList();
// install apk (note that variant.getOutputFile() will point to a .aar in the case of a library)
int projectType = androidModel.getProjectType();
if (projectType == PROJECT_TYPE_APP || projectType == PROJECT_TYPE_INSTANTAPP) {
File apk = getApk(selectedVariant, device);
apkList.add(new ApkInfo(apk, myApplicationIdProvider.getPackageName()));
}
if (myTest) {
AndroidArtifact testArtifactInfo = androidModel.getAndroidTestArtifactInSelectedVariant();
if (testArtifactInfo != null) {
AndroidArtifactOutput output = GradleUtil.getOutput(testArtifactInfo);
File testApk = output.getMainOutputFile().getOutputFile();
String testPackageName = myApplicationIdProvider.getTestPackageName();
// Cannot be null if initialized.
assert testPackageName != null;
apkList.add(new ApkInfo(testApk, testPackageName));
}
if (androidModel.getFeatures().isTestedTargetVariantsSupported()) {
apkList.addAll(0, getTargetedApks(selectedVariant, device));
}
}
return apkList;
}
use of com.android.builder.model.AndroidArtifact in project android by JetBrains.
the class AnalyzeApkAction method getLastSelectedApk.
@Nullable
private static VirtualFile getLastSelectedApk(Project project) {
String lastApkPath = PropertiesComponent.getInstance(project).getValue(LAST_APK_PATH);
if (lastApkPath != null) {
File f = new File(lastApkPath);
if (f.exists()) {
return VfsUtil.findFileByIoFile(f, true);
}
}
// see if we can find an apk generated by gradle if this is the first time
for (Module module : ModuleManager.getInstance(project).getModules()) {
AndroidModuleModel model = AndroidModuleModel.get(module);
if (model == null) {
continue;
}
if (model.getProjectType() != PROJECT_TYPE_APP) {
continue;
}
AndroidArtifact mainArtifact = model.getSelectedVariant().getMainArtifact();
for (AndroidArtifactOutput output : mainArtifact.getOutputs()) {
File outputFile = output.getMainOutputFile().getOutputFile();
if (outputFile.exists()) {
return VfsUtil.findFileByIoFile(outputFile, true);
}
}
}
return null;
}
use of com.android.builder.model.AndroidArtifact in project android by JetBrains.
the class AndroidGradleClassJarProvider method getCompilerOutputRoot.
@Nullable
private static VirtualFile getCompilerOutputRoot(@NotNull AndroidModuleModel model) {
Variant variant = model.getSelectedVariant();
String variantName = variant.getName();
AndroidArtifact mainArtifactInfo = model.getMainArtifact();
File classesFolder = mainArtifactInfo.getClassesFolder();
//noinspection ConstantConditions
if (classesFolder == null) {
// For getOutput()
@SuppressWarnings("deprecation") AndroidArtifactOutput output = GradleUtil.getOutput(mainArtifactInfo);
File file = output.getMainOutputFile().getOutputFile();
File buildFolder = file.getParentFile().getParentFile();
// See AndroidContentRoot
classesFolder = new File(buildFolder, "classes");
}
File outFolder = new File(classesFolder, // Change variant name variant-release into variant/release directories
variantName.replace('-', File.separatorChar));
if (outFolder.exists()) {
return VfsUtil.findFileByIoFile(outFolder, true);
}
return null;
}
Aggregations