use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class LaunchCompatibilityCheckerImpl method create.
public static LaunchCompatibilityChecker create(@NotNull AndroidFacet facet) {
AndroidVersion minSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
throw new IllegalStateException("Android platform not set for module: " + facet.getModule().getName());
}
// Currently, we only look at whether the device supports the watch feature.
// We may not want to search the device for every possible feature, but only a small subset of important
// features, starting with hardware type watch.
EnumSet<IDevice.HardwareFeature> requiredHardwareFeatures;
if (LaunchUtils.isWatchFeatureRequired(facet)) {
requiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
} else {
requiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
}
Set<String> supportedAbis = facet.getAndroidModel() instanceof AndroidModuleModel ? ((AndroidModuleModel) facet.getAndroidModel()).getSelectedVariant().getMainArtifact().getAbiFilters() : null;
return new LaunchCompatibilityCheckerImpl(minSdkVersion, platform.getTarget(), requiredHardwareFeatures, supportedAbis);
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class GradleApkProvider method validate.
@NotNull
@Override
public List<ValidationError> validate() {
AndroidModuleModel androidModuleModel = AndroidModuleModel.get(myFacet);
// This is a Gradle project, there must be an AndroidGradleModel.
assert androidModuleModel != null;
if (androidModuleModel.getMainArtifact().isSigned()) {
return ImmutableList.of();
}
AndroidArtifactOutput output = GradleUtil.getOutput(androidModuleModel.getMainArtifact());
final String message = AndroidBundle.message("run.error.apk.not.signed", output.getMainOutputFile().getOutputFile().getName(), androidModuleModel.getSelectedVariant().getDisplayName());
Runnable quickFix = new Runnable() {
@Override
public void run() {
Module module = myFacet.getModule();
ProjectSettingsService service = ProjectSettingsService.getInstance(module.getProject());
if (service instanceof AndroidProjectSettingsService) {
((AndroidProjectSettingsService) service).openSigningConfiguration(module);
} else {
service.openModuleSettings(module);
}
}
};
return ImmutableList.of(ValidationError.fatal(message, quickFix));
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class GradleApkProvider method getTargetedApks.
/**
* Gets the list of targeted apks for the specified variant.
*
* <p>This is used for test-only modules when specifying the tested apk
* using the targetProjectPath and targetVariant properties in the build file.
*/
@NotNull
private List<ApkInfo> getTargetedApks(@NotNull Variant selectedVariant, @NotNull IDevice device) throws ApkProvisionException {
List<ApkInfo> targetedApks = Lists.newArrayList();
for (TestedTargetVariant testedVariant : getTestedTargetVariants(selectedVariant)) {
Module targetModule = ApplicationManager.getApplication().runReadAction((Computable<Module>) () -> GradleUtil.findModuleByGradlePath(myFacet.getModule().getProject(), testedVariant.getTargetProjectPath()));
// target module has to exist, otherwise we would not be able to build test apk
assert targetModule != null;
AndroidFacet targetFacet = AndroidFacet.getInstance(targetModule);
if (targetFacet == null) {
LOG.warn("Please install tested apk manually.");
continue;
}
AndroidModuleModel targetAndroidModel = AndroidModuleModel.get(targetFacet);
if (targetAndroidModel == null) {
LOG.warn("Android model for tested module is null. Sync might have failed.");
continue;
}
Variant targetVariant = targetAndroidModel.findVariantByName(testedVariant.getTargetVariant());
if (targetVariant == null) {
LOG.warn("Tested variant not found. Sync might have failed.");
continue;
}
File targetApk = getApk(targetVariant, device);
targetedApks.add(new ApkInfo(targetApk, targetVariant.getMergedFlavor().getApplicationId()));
}
return targetedApks;
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class AndroidJunitPatcher method handleJavaResources.
/**
* Puts folders with merged java resources for the selected variant of every module on the classpath.
*
* <p>The problem we're solving here is that CompilerModuleExtension supports only one directory for "compiler output". When IJ compiles
* Java projects, it copies resources to the output classes dir. This is something our Gradle plugin doesn't do, so we need to add the
* resource directories to the classpath here.
*
* <p>We need to do this for every project dependency as well, since we're using classes and resources directories of these directly.
*
* @see <a href="http://b.android.com/172409">Bug 172409</a>
*/
private static void handleJavaResources(@NotNull Module module, @NotNull AndroidModuleModel androidModel, @NotNull PathsList classPath) {
CompilerManager compilerManager = CompilerManager.getInstance(module.getProject());
CompileScope scope = compilerManager.createModulesCompileScope(new Module[] { module }, true, true);
// The only test resources we want to use, are the ones from the module where the test is. They should go first, before main resources.
JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
if (testArtifact != null) {
try {
classPath.add(testArtifact.getJavaResourcesFolder());
} catch (UnsupportedMethodException ignored) {
// Java resources were not present in older versions of the gradle plugin.
}
}
FileRootSearchScope excludeScope = null;
TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
if (testScopes != null) {
excludeScope = testScopes.getUnitTestExcludeScope();
}
for (Module affectedModule : scope.getAffectedModules()) {
AndroidFacet facet = AndroidFacet.getInstance(affectedModule);
if (facet != null) {
AndroidModuleModel affectedAndroidModel = AndroidModuleModel.get(facet);
if (affectedAndroidModel != null) {
try {
File resourceFolder = affectedAndroidModel.getMainArtifact().getJavaResourcesFolder();
if (excludeScope != null && excludeScope.accept(resourceFolder)) {
continue;
}
classPath.add(resourceFolder);
} catch (UnsupportedMethodException ignored) {
// Java resources were not present in older versions of the gradle plugin.
}
}
}
}
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class ExcludedRoots method addModuleIfNecessary.
private void addModuleIfNecessary(@NotNull Module module) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
BaseArtifact unitTestArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
BaseArtifact androidTestArtifact = androidModel.getAndroidTestArtifactInSelectedVariant();
BaseArtifact excludeArtifact = myAndroidTest ? unitTestArtifact : androidTestArtifact;
BaseArtifact includeArtifact = myAndroidTest ? androidTestArtifact : unitTestArtifact;
if (excludeArtifact != null) {
processFolders(excludeArtifact, androidModel, myExcludedRoots::add);
}
if (includeArtifact != null) {
processFolders(includeArtifact, androidModel, myExcludedRoots::remove);
}
}
}
Aggregations