use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class GradleUtil method setBuildToolsVersion.
public static void setBuildToolsVersion(@NotNull Project project, @NotNull String version) {
List<GradleBuildModel> modelsToUpdate = Lists.newArrayList();
for (Module module : ModuleManager.getInstance(project).getModules()) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
AndroidModel android = buildModel.android();
if (android != null && !version.equals(android.buildToolsVersion().value())) {
android.setBuildToolsVersion(version);
modelsToUpdate.add(buildModel);
}
}
}
}
if (!modelsToUpdate.isEmpty()) {
runWriteCommandAction(project, () -> {
for (GradleBuildModel buildModel : modelsToUpdate) {
buildModel.applyChanges();
}
});
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ConflictResolution method solveSelectionConflict.
private static boolean solveSelectionConflict(@NotNull Conflict conflict, boolean showConflictResolutionDialog) {
AndroidFacet facet = AndroidFacet.getInstance(conflict.getSource());
if (facet == null || !facet.requiresAndroidModel()) {
// project structure may have changed and the conflict is not longer applicable.
return true;
}
AndroidModuleModel source = AndroidModuleModel.get(facet);
if (source == null) {
return false;
}
Collection<String> variants = conflict.getVariants();
if (variants.size() == 1) {
String expectedVariant = getFirstItem(variants);
if (isNotEmpty(expectedVariant)) {
source.setSelectedVariantName(expectedVariant);
source.syncSelectedVariantAndTestArtifact(facet);
return true;
}
} else if (showConflictResolutionDialog) {
ConflictResolutionDialog dialog = new ConflictResolutionDialog(conflict);
if (dialog.showAndGet()) {
String selectedVariant = dialog.getSelectedVariant();
if (isNotEmpty(selectedVariant)) {
source.setSelectedVariantName(selectedVariant);
source.syncSelectedVariantAndTestArtifact(facet);
return true;
}
}
}
return false;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AddAndroidActivityPath method getDirectories.
private Map<String, Object> getDirectories() {
Map<String, Object> templateParameters = Maps.newHashMap();
Module module = getModule();
assert module != null;
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
}
// Read minSdkVersion and package from manifest and/or build.gradle files
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
AndroidModel androidModel = facet.getAndroidModel();
SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
if (sourceProvider1 != null && androidModel != null) {
String packageName = myState.get(KEY_PACKAGE_NAME);
assert packageName != null;
templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
}
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
String minSdkName = minSdkVersion.getApiString();
templateParameters.put(ATTR_MIN_API, minSdkName);
templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
try {
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
} catch (Exception e) {
LOG.info("Could not compute SHA1 hash of debug keystore.", e);
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
}
@SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
Project project = getProject();
assert project != null;
templateParameters.put(projectLocation, project.getBasePath());
// 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 = new File(module.getModuleFilePath()).getParentFile().getName();
templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
return templateParameters;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AppResourceRepository method findAarLibraries.
@NotNull
public static Collection<AndroidLibrary> findAarLibraries(@NotNull AndroidFacet facet) {
List<AndroidLibrary> libraries = Lists.newArrayList();
if (facet.requiresAndroidModel()) {
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(facet.getModule(), true);
addGradleLibraries(libraries, androidModel);
for (AndroidFacet dependentFacet : dependentFacets) {
AndroidModuleModel dependentGradleModel = AndroidModuleModel.get(dependentFacet);
if (dependentGradleModel != null) {
addGradleLibraries(libraries, dependentGradleModel);
}
}
}
}
return libraries;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AppResourceRepository method findAarLibrariesFromGradle.
/**
* Looks up the library dependencies from the Gradle tools model and returns the corresponding {@code .aar}
* resource directories.
*/
@NotNull
private static Map<File, String> findAarLibrariesFromGradle(@NotNull GradleVersion modelVersion, List<AndroidFacet> dependentFacets, List<AndroidLibrary> libraries) {
// Pull out the unique directories, in case multiple modules point to the same .aar folder
Map<File, String> files = new HashMap<>(libraries.size());
Set<String> moduleNames = Sets.newHashSet();
for (AndroidFacet f : dependentFacets) {
moduleNames.add(f.getModule().getName());
}
try {
for (AndroidLibrary library : libraries) {
// We should only add .aar dependencies if they aren't already provided as modules.
// For now, the way we associate them with each other is via the library name;
// in the future the model will provide this for us
String libraryName = null;
String projectName = library.getProject();
if (projectName != null && !projectName.isEmpty()) {
libraryName = projectName.substring(projectName.lastIndexOf(':') + 1);
// Since this library has project!=null, it exists in module form; don't
// add it here.
moduleNames.add(libraryName);
continue;
} else {
File folder = library.getFolder();
String name = folder.getName();
if (modelVersion.getMajor() > 2 || modelVersion.getMajor() == 2 && modelVersion.getMinor() >= 2) {
// Library.getName() was added in 2.2
libraryName = library.getName();
} else if (name.endsWith(DOT_AAR)) {
libraryName = name.substring(0, name.length() - DOT_AAR.length());
} else if (folder.getPath().contains(AndroidModuleModel.EXPLODED_AAR)) {
libraryName = folder.getParentFile().getName();
}
}
if (libraryName != null && !moduleNames.contains(libraryName)) {
File resFolder = library.getResFolder();
if (resFolder.exists()) {
files.put(resFolder, libraryName);
// Don't add it again!
moduleNames.add(libraryName);
}
}
}
} catch (UnsupportedMethodException e) {
// This happens when there is an incompatibility between the builder-model interfaces embedded in Android Studio and the
// cached model.
// If we got here is because this code got invoked before project sync happened (e.g. when reopening a project with open editors).
// Project sync now is smart enough to handle this case and will trigger a full sync.
LOG.warn("Incompatibility found between the IDE's builder-model and the cached Gradle model", e);
}
return files;
}
Aggregations