Search in sources :

Example 46 with AndroidLibrary

use of com.android.builder.model.AndroidLibrary in project android by JetBrains.

the class BuildVariantUpdater method updateSelectedVariant.

private boolean updateSelectedVariant(@NotNull AndroidFacet androidFacet, @NotNull AndroidModuleModel androidModel, @NotNull String variantToSelect, @NotNull List<AndroidFacet> affectedFacets) {
    Variant selectedVariant = androidModel.getSelectedVariant();
    if (variantToSelect.equals(selectedVariant.getName())) {
        return false;
    }
    androidModel.setSelectedVariantName(variantToSelect);
    androidModel.syncSelectedVariantAndTestArtifact(androidFacet);
    Module module = setUpModule(androidFacet.getModule(), androidModel);
    for (AndroidLibrary library : androidModel.getSelectedMainCompileDependencies().getLibraries()) {
        String gradlePath = library.getProject();
        if (isEmpty(gradlePath)) {
            continue;
        }
        String projectVariant = library.getProjectVariant();
        if (isNotEmpty(projectVariant)) {
            ensureVariantIsSelected(module.getProject(), gradlePath, projectVariant, affectedFacets);
        }
    }
    return true;
}
Also used : NdkVariant(com.android.tools.idea.gradle.project.model.NdkModuleModel.NdkVariant) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module)

Example 47 with AndroidLibrary

use of com.android.builder.model.AndroidLibrary in project android by JetBrains.

the class GeneratedCodeMatchTest method findViewDataBindingClass.

@NotNull
private ClassReader findViewDataBindingClass() throws IOException {
    File classes = null;
    AndroidModuleModel model = AndroidModuleModel.get(myAndroidFacet);
    for (AndroidLibrary lib : model.getMainArtifact().getDependencies().getLibraries()) {
        if (lib.getName().startsWith("com.android.databinding:library")) {
            classes = lib.getJarFile();
        }
    }
    assert classes != null;
    assertTrue(classes.exists());
    try (JarFile classesJar = new JarFile(classes, true)) {
        ZipEntry entry = classesJar.getEntry(SdkConstants.CLASS_DATA_BINDING_BASE_BINDING.replace(".", "/") + ".class");
        assertNotNull(entry);
        return new ClassReader(classesJar.getInputStream(entry));
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) ZipEntry(java.util.zip.ZipEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with AndroidLibrary

use of com.android.builder.model.AndroidLibrary in project meghanada-server by mopemope.

the class AndroidSupport method parseExtraJavaArtifacts.

private void parseExtraJavaArtifacts(Set<ProjectDependency> dependencies, Variant variant) {
    String buildType = variant.getBuildType();
    boolean debugBuild = buildType.equals(DEBUG_BUILD);
    Collection<JavaArtifact> extraJavaArtifacts = variant.getExtraJavaArtifacts();
    for (JavaArtifact javaArtifact : extraJavaArtifacts) {
        if (debugBuild) {
            Collection<File> generatedSourceFolders = javaArtifact.getGeneratedSourceFolders();
            for (File src : generatedSourceFolders) {
                this.project.getSources().add(src);
            }
        }
        Dependencies compileDependencies = javaArtifact.getDependencies();
        Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
        for (AndroidLibrary androidLibrary : libraries) {
            Collection<File> localJars = androidLibrary.getLocalJars();
            for (File jar : localJars) {
                addDependencies(dependencies, jar);
            }
        }
        Collection<JavaLibrary> javaLibraries = compileDependencies.getJavaLibraries();
        for (JavaLibrary javaLibrary : javaLibraries) {
            File file = javaLibrary.getJarFile();
            addDependencies(dependencies, file);
        }
    }
}
Also used : JavaArtifact(com.android.builder.model.JavaArtifact) JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) Dependencies(com.android.builder.model.Dependencies) File(java.io.File)

Example 49 with AndroidLibrary

use of com.android.builder.model.AndroidLibrary in project meghanada-server by mopemope.

the class AndroidSupport method parseExtraAndroidArtifacts.

private void parseExtraAndroidArtifacts(Set<ProjectDependency> dependencies, Variant variant) {
    String buildType = variant.getBuildType();
    boolean debugBuild = buildType.equals(DEBUG_BUILD);
    Collection<AndroidArtifact> extraAndroidArtifacts = variant.getExtraAndroidArtifacts();
    for (AndroidArtifact androidArtifact : extraAndroidArtifacts) {
        String name = androidArtifact.getName();
        boolean isTest = name.contains(TEST_SUFFIX);
        if (debugBuild) {
            Collection<File> generatedSourceFolders = androidArtifact.getGeneratedSourceFolders();
            for (File src : generatedSourceFolders) {
                if (isTest) {
                    this.project.getTestSources().add(src);
                } else {
                    this.project.getSources().add(src);
                }
            }
            Collection<File> generatedResourceFolders = androidArtifact.getGeneratedResourceFolders();
            for (File src : generatedResourceFolders) {
                if (isTest) {
                    this.project.getTestResources().add(src);
                } else {
                    this.project.getResources().add(src);
                }
            }
        }
        Dependencies compileDependencies = androidArtifact.getDependencies();
        // getLibraries
        Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
        for (AndroidLibrary androidLibrary : libraries) {
            Collection<File> localJars = androidLibrary.getLocalJars();
            if (localJars.isEmpty()) {
                File jar = androidLibrary.getJarFile();
                addDependencies(dependencies, jar);
            } else {
                for (File jar : localJars) {
                    addDependencies(dependencies, jar);
                }
            }
        }
        // getJavaLibraries
        Collection<JavaLibrary> javaLibraries = compileDependencies.getJavaLibraries();
        for (JavaLibrary javaLibrary : javaLibraries) {
            File file = javaLibrary.getJarFile();
            addDependencies(dependencies, file);
        }
    }
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) Dependencies(com.android.builder.model.Dependencies) AndroidArtifact(com.android.builder.model.AndroidArtifact) File(java.io.File)

Example 50 with AndroidLibrary

use of com.android.builder.model.AndroidLibrary in project atlas by alibaba.

the class AtlasDataBindingMergeArtifactsTransform method processAwbsDataBindings.

private void processAwbsDataBindings() throws IOException {
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getVariantName());
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        File awbDataBindDepsOutDir = variantContext.getAwbDataBindingMergeArtifacts(awbBundle);
        for (AndroidLibrary androidLibrary : awbBundle.getAndroidLibraries()) {
            File artifactFolder = new File(androidLibrary.getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
            if (artifactFolder.exists() && artifactFolder.listFiles() != null) {
                for (String artifactName : artifactFolder.list()) {
                    if (isResource(artifactName)) {
                        FileUtils.copyFile(new File(artifactFolder, artifactName), new File(awbDataBindDepsOutDir, artifactName));
                    }
                }
            }
        }
        File awbDataBindDir = new File(awbBundle.getAndroidLibrary().getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
        if (awbDataBindDir.exists() && awbDataBindDir.listFiles() != null) {
            for (String artifactName : awbDataBindDir.list()) {
                if (isResource(artifactName)) {
                    FileUtils.copyFile(new File(awbDataBindDir, artifactName), new File(awbDataBindDepsOutDir, artifactName));
                }
            }
        }
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) File(java.io.File)

Aggregations

AndroidLibrary (com.android.builder.model.AndroidLibrary)59 File (java.io.File)39 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)13 JavaLibrary (com.android.builder.model.JavaLibrary)11 ArrayList (java.util.ArrayList)11 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)8 TaskAction (org.gradle.api.tasks.TaskAction)8 NotNull (org.jetbrains.annotations.NotNull)8 GradleException (org.gradle.api.GradleException)6 VariantScope (com.android.build.gradle.internal.scope.VariantScope)5 MavenCoordinates (com.android.builder.model.MavenCoordinates)5 Variant (com.android.builder.model.Variant)5 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)5 Module (com.intellij.openapi.module.Module)5 JarFile (java.util.jar.JarFile)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 InputFile (org.gradle.api.tasks.InputFile)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4