Search in sources :

Example 16 with AndroidLibrary

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

the class ModuleVariantsInfoDialog method createDependenciesTree.

@NotNull
private static JTree createDependenciesTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (value instanceof DefaultMutableTreeNode) {
                Object data = ((DefaultMutableTreeNode) value).getUserObject();
                if (data instanceof String) {
                    appendVariant((String) data);
                } else if (data instanceof DependencyTreeElement) {
                    DependencyTreeElement dependency = (DependencyTreeElement) data;
                    appendModule(dependency.myModule, dependency.myVariant);
                }
            }
        }
    };
    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;
    Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();
    for (Variant variant : androidProject.getVariants()) {
        for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
            String gradlePath = library.getProject();
            if (gradlePath == null) {
                continue;
            }
            Module dependency = GradleUtil.findModuleByGradlePath(module.getProject(), gradlePath);
            if (dependency != null) {
                DependencyTreeElement element = new DependencyTreeElement(dependency, library.getProjectVariant());
                dependenciesByVariant.put(variant.getName(), element);
            }
        }
    }
    // Consolidate variants. This means if "debug" and "release" have the same dependencies, we show only one node as "debug, release".
    List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet());
    Collections.sort(variantNames);
    List<String> consolidatedVariants = Lists.newArrayList();
    List<String> variantsToSkip = Lists.newArrayList();
    int variantCount = variantNames.size();
    for (int i = 0; i < variantCount; i++) {
        String variant1 = variantNames.get(i);
        if (variantsToSkip.contains(variant1)) {
            continue;
        }
        Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1);
        for (int j = i + 1; j < variantCount; j++) {
            String variant2 = variantNames.get(j);
            Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2);
            if (set1.equals(set2)) {
                variantsToSkip.add(variant2);
                if (!consolidatedVariants.contains(variant1)) {
                    consolidatedVariants.add(variant1);
                }
                consolidatedVariants.add(variant2);
            }
        }
        String variantName = variant1;
        if (!consolidatedVariants.isEmpty()) {
            variantName = Joiner.on(", ").join(consolidatedVariants);
        }
        DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
        root.add(variantNode);
        List<DependencyTreeElement> dependencies = Lists.newArrayList(set1);
        Collections.sort(dependencies);
        for (DependencyTreeElement dependency : dependencies) {
            variantNode.add(new DefaultMutableTreeNode(dependency));
        }
        consolidatedVariants.clear();
    }
    CheckboxTree tree = new CheckboxTree(renderer, root);
    tree.setRootVisible(false);
    TreeUtil.expandAll(tree);
    return tree;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckboxTree(com.intellij.ui.CheckboxTree) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) AndroidProject(com.android.builder.model.AndroidProject) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module) VariantCheckboxTreeCellRenderer(com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with AndroidLibrary

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

the class AndroidResourceRenameResourceProcessor method appendUnhandledReferences.

/** Writes into the given {@link HtmlBuilder} a set of references
   * that are defined in a library (and may or may not also be defined locally) */
private static void appendUnhandledReferences(@NotNull Project project, @NotNull AndroidFacet facet, @NotNull List<ResourceItem> all, @NotNull List<ResourceItem> local, @NotNull HtmlBuilder builder) {
    File root = VfsUtilCore.virtualToIoFile(project.getBaseDir());
    Collection<AndroidLibrary> libraries = null;
    // Write a set of descriptions to library references. Put them in a list first such that we can
    // sort the (to for example make test output stable.)
    List<String> descriptions = Lists.newArrayList();
    for (ResourceItem item : all) {
        if (!local.contains(item)) {
            ResourceFile source = item.getSource();
            if (libraries == null) {
                libraries = AppResourceRepository.findAarLibraries(facet);
            }
            if (source != null) {
                File sourceFile = source.getFile();
                // TODO: Look up the corresponding AAR artifact, and then use library.getRequestedCoordinates() or
                // library.getResolvedCoordinates() here and append the coordinate. However, until b.android.com/77341
                // is fixed this doesn't work.
                /*
          // Attempt to find the corresponding AAR artifact
          AndroidLibrary library = null;
          for (AndroidLibrary l : libraries) {
            File res = l.getResFolder();
            if (res.exists() && FileUtil.isAncestor(res, sourceFile, true)) {
              library = l;
              break;
            }
          }
          */
                // Look for exploded-aar and strip off the prefix path to it
                File localRoot = root;
                File prev = sourceFile;
                File current = sourceFile.getParentFile();
                while (current != null) {
                    String name = current.getName();
                    if (EXPLODED_AAR.equals(name)) {
                        localRoot = prev;
                        break;
                    }
                    prev = current;
                    current = current.getParentFile();
                }
                if (FileUtil.isAncestor(localRoot, sourceFile, true)) {
                    descriptions.add(FileUtil.getRelativePath(localRoot, sourceFile));
                } else {
                    descriptions.add(sourceFile.getPath());
                }
            }
        }
    }
    Collections.sort(descriptions);
    builder.newline().newline();
    builder.add("Unhandled references:");
    builder.newline();
    int count = 0;
    for (String s : descriptions) {
        builder.add(s).newline();
        count++;
        if (count == 10) {
            builder.add("...").newline();
            builder.add("(Additional results truncated)");
            break;
        }
    }
}
Also used : ResourceFile(com.android.ide.common.res2.ResourceFile) AndroidLibrary(com.android.builder.model.AndroidLibrary) ResourceItem(com.android.ide.common.res2.ResourceItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) File(java.io.File)

Example 18 with AndroidLibrary

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

the class Inspector method inspect.

private void inspect(AndroidLibrary androidLibrary) {
    libsByEquality.add(androidLibrary);
    libsByFile.put(androidLibrary.getJarFile(), androidLibrary);
    libsByIdentity.put(androidLibrary, androidLibrary);
    unpack(androidLibrary, libsBackingByIdentity);
    for (AndroidLibrary library : androidLibrary.getLibraryDependencies()) {
        inspect(library);
    }
    for (JavaLibrary library : androidLibrary.getJavaDependencies()) {
        inspect(library);
    }
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary)

Example 19 with AndroidLibrary

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

the class MergeAwbAssetConfigAction method execute.

@Override
public void execute(MergeSourceSetFolders task) {
    final VariantScope scope = variantContext.getScope();
    BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();
    final VariantConfiguration variantConfig = variantData.getVariantConfiguration();
    task.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    task.setVariantName(variantConfig.getFullName());
    task.setIncrementalFolder(scope.getIncrementalDir(getName()));
    ConventionMappingHelper.map(task, "inputDirectorySets", new Callable<List<AssetSet>>() {

        @Override
        public List<AssetSet> call() throws Exception {
            List<AssetSet> assetSets = Lists.newArrayList();
            List<? extends AndroidLibrary> bundleDeps = awbBundle.getLibraryDependencies();
            // the list of dependency must be reversed to use the right overlay order.
            for (int n = bundleDeps.size() - 1; n >= 0; n--) {
                AndroidLibrary dependency = bundleDeps.get(n);
                File assetFolder = dependency.getAssetsFolder();
                if (assetFolder.isDirectory()) {
                    AssetSet assetSet = new AssetSet(dependency.getFolder().getName());
                    assetSet.addSource(assetFolder);
                    assetSets.add(assetSet);
                }
            }
            File awbAssetFolder = awbBundle.getAssetsFolder();
            if (awbAssetFolder.isDirectory()) {
                AssetSet awbAssetSet = new AssetSet(awbBundle.getFolder().getName());
                awbAssetSet.addSource(awbAssetFolder);
                assetSets.add(awbAssetSet);
            }
            return assetSets;
        }
    });
    ConventionMappingHelper.map(task, "outputDir", new Callable<File>() {

        @Override
        public File call() throws Exception {
            GlobalScope globalScope = scope.getGlobalScope();
            return variantContext.getMergeAssets(awbBundle);
        }
    });
//        if (variantContext instanceof AppVariantContext) {
//            AppVariantContext appVariantContext = (AppVariantContext) variantContext;
//            appVariantContext.getAwbMergeAssetTasks().put(awbBundle.getName(), task);
//        }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) AndroidLibrary(com.android.builder.model.AndroidLibrary) AssetSet(com.android.ide.common.res2.AssetSet) List(java.util.List) File(java.io.File) VariantConfiguration(com.android.builder.core.VariantConfiguration)

Example 20 with AndroidLibrary

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

the class PrepareSoLibTask method generate.

/**
     * 生成so的目录
     */
@TaskAction
void generate() {
    List<File> scanDirs = new ArrayList<File>();
    //先生成主bundle的jnifolder目录
    if (!getMainBundleOutputFolder().exists()) {
        getMainBundleOutputFolder().mkdirs();
    }
    for (File jniFolder : getJniFolders()) {
        if (jniFolder.exists() && jniFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(jniFolder, getMainBundleOutputFolder(), getSupportAbis(), getRemoveSoFiles(), getILogger());
        }
    }
    scanDirs.add(getMainBundleOutputFolder());
    //增加主bundle依赖的solib的so
    for (SoLibrary mainSoLib : getMainDexSoLibraries()) {
        File explodeFolder = mainSoLib.getFolder();
        if (explodeFolder.exists() && explodeFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(explodeFolder, getMainBundleOutputFolder(), getSupportAbis(), getRemoveSoFiles(), getILogger());
        }
    }
    //处理awb bundle的so
    for (AwbBundle awbLib : getAwbLibs()) {
        File awbOutputFolder = new File(appVariantOutputContext.getAwbJniFolder(awbLib), "lib");
        awbOutputFolder.mkdirs();
        scanDirs.add(awbOutputFolder);
        File awbJniFolder = awbLib.getJniFolder();
        if (awbJniFolder.exists() && awbJniFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(awbJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
        }
        //为了兼容之前老的aar,awb格式
        File libJniFolder = new File(awbLib.getFolder(), "libs");
        if (libJniFolder.exists() && libJniFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(libJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
        }
        List<? extends AndroidLibrary> deps = awbLib.getLibraryDependencies();
        for (AndroidLibrary dep : deps) {
            File depJniFolder = dep.getJniFolder();
            if (depJniFolder.exists() && depJniFolder.isDirectory()) {
                NativeSoUtils.copyLocalNativeLibraries(depJniFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
            }
            //为了兼容之前老的aar,awb格式
            File depLibsFolder = new File(dep.getFolder(), "libs");
            if (depLibsFolder.exists() && depLibsFolder.isDirectory()) {
                NativeSoUtils.copyLocalNativeLibraries(depLibsFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
            }
        }
        List<SoLibrary> solibs = awbLib.getSoLibraries();
        if (null != solibs) {
            for (SoLibrary solib : solibs) {
                File explodeFolder = solib.getFolder();
                if (explodeFolder.exists() && explodeFolder.isDirectory()) {
                    NativeSoUtils.copyLocalNativeLibraries(explodeFolder, awbOutputFolder, getSupportAbis(), getRemoveSoFiles(), getILogger());
                }
            }
        }
    }
    //判断是否有重复的so文件
    // 进行重复文件的查询
    Map<String, Multimap<String, File>> soMaps = NativeSoUtils.getAbiSoFiles(getSupportAbis(), getRemoveSoFiles(), scanDirs);
    boolean hasDup = false;
    for (Map.Entry<String, Multimap<String, File>> entry : soMaps.entrySet()) {
        String abi = entry.getKey();
        Multimap<String, File> soFiles = soMaps.get(abi);
        for (String soKey : soFiles.keys()) {
            if (soFiles.get(soKey).size() > 1) {
                getILogger().warning("[SO Duplicate][" + abi + "]:" + StringUtils.join(soFiles.get(soKey), ","));
                hasDup = true;
            } else {
                getILogger().verbose("[SO][" + abi + "]:" + StringUtils.join(soFiles.get(soKey), ","));
            }
        }
    }
//        if (hasDup && getFailOnDuplicateSo()) {
//            throw new RuntimeException("SO file has duplicate files!See detail info!");
//        }
}
Also used : SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) Multimap(com.google.common.collect.Multimap) AndroidLibrary(com.android.builder.model.AndroidLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

AndroidLibrary (com.android.builder.model.AndroidLibrary)33 File (java.io.File)18 NotNull (org.jetbrains.annotations.NotNull)6 JavaLibrary (com.android.builder.model.JavaLibrary)5 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)5 Module (com.intellij.openapi.module.Module)5 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)5 MavenCoordinates (com.android.builder.model.MavenCoordinates)4 Variant (com.android.builder.model.Variant)4 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)4 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)4 InputFile (org.gradle.api.tasks.InputFile)4 TaskAction (org.gradle.api.tasks.TaskAction)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4 VariantScope (com.android.build.gradle.internal.scope.VariantScope)3 HashSet (java.util.HashSet)3 List (java.util.List)3 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 SymbolLoader (com.android.builder.internal.SymbolLoader)2 SymbolWriter (com.android.builder.internal.SymbolWriter)2