Search in sources :

Example 6 with AndroidLibrary

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

the class DiffDependencyTask method doTask.

@TaskAction
public void doTask() throws IOException {
    apDependenciesFile = getApDependenciesFile();
    diffOutFile = getDiffOutFile();
    DependencyJson apDependencyJson = JSON.parseObject(FileUtils.readFileToString(apDependenciesFile), DependencyJson.class);
    Set<String> apMainDependencies = Sets.newHashSet();
    for (String mainDep : apDependencyJson.getMainDex()) {
        String name = mainDep.substring(0, mainDep.lastIndexOf(":"));
        apMainDependencies.add(name);
    }
    AwbBundle awbBundle = libVariantContext.getAwbBundle();
    //aars
    if (null != awbBundle.getLibraryDependencies()) {
        for (int index = 0; index < awbBundle.getLibraryDependencies().size(); index++) {
            AndroidLibrary libraryDependency = awbBundle.getLibraryDependencies().get(index);
            MavenCoordinates mavenCoordinates = libraryDependency.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getLibraryDependencies().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    //solibs
    if (null != awbBundle.getSoLibraries()) {
        for (int index = 0; index < awbBundle.getSoLibraries().size(); index++) {
            SoLibrary soLibrary = awbBundle.getSoLibraries().get(index);
            MavenCoordinates mavenCoordinates = soLibrary.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getSoLibraries().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    // jars
    if (null != awbBundle.getJavaDependencies()) {
        Iterator<? extends JavaLibrary> iterator = awbBundle.getJavaDependencies().iterator();
        while (iterator.hasNext()) {
            JavaLibrary jarInfo = iterator.next();
            MavenCoordinates mavenCoordinates = jarInfo.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                iterator.remove();
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    FileUtils.writeStringToFile(diffOutFile, StringUtils.join(inAwbDependencies, "\n"));
}
Also used : MavenCoordinates(com.android.builder.model.MavenCoordinates) JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with AndroidLibrary

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

the class MergeAwoManifests method getLibraryManifests.

/**
     * A synthetic input to allow gradle up-to-date checks to work.
     * <p>
     * Since List<ManifestDependencyImpl> can't be used directly, as @Nested doesn't work on lists,
     * this method gathers and returns the underlying manifest files.
     */
@SuppressWarnings("unused")
@InputFiles
List<File> getLibraryManifests() {
    List<? extends AndroidLibrary> libs = getLibraries();
    if (libs == null || libs.isEmpty()) {
        return Collections.emptyList();
    }
    List<File> files = Lists.newArrayListWithCapacity(libs.size() * 2);
    for (AndroidLibrary mdi : libs) {
        files.add(mdi.getManifest());
    }
    return files;
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile) InputFiles(org.gradle.api.tasks.InputFiles)

Example 8 with AndroidLibrary

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

the class DependencyTree method toAndroidDependency.

/**
     * 转换为Android的依赖
     *
     * @return
     */
public AndroidDependencyTree toAndroidDependency() {
    AndroidDependencyTree androidDependencyTree = new AndroidDependencyTree(mResolvedDependencies);
    for (ResolvedDependencyInfo dependencyInfo : mResolvedDependencies) {
        switch(DependencyConvertUtils.Type.getType(dependencyInfo.getType())) {
            case AAR:
                AarBundle aarBundle = DependencyConvertUtils.toAarBundle(dependencyInfo);
                androidDependencyTree.getAarBundles().add(aarBundle);
                for (AndroidLibrary libraryDependency : aarBundle.getLibraryDependencies()) {
                    if (libraryDependency instanceof AarBundle) {
                        androidDependencyTree.getAarBundles().add((AarBundle) libraryDependency);
                    }
                }
                androidDependencyTree.getJars().addAll(aarBundle.getJavaDependencies());
                androidDependencyTree.getSoLibraries().addAll(aarBundle.getSoLibraries());
                break;
            case AWB:
                AwbBundle awbBundle = DependencyConvertUtils.toAwbBundle(dependencyInfo);
                androidDependencyTree.getAwbBundles().add(awbBundle);
                break;
            case JAR:
                JavaLibrary jarInfo = DependencyConvertUtils.toJarDependency(dependencyInfo);
                androidDependencyTree.getJars().add(jarInfo);
                androidDependencyTree.getJars().addAll(jarInfo.getDependencies());
                break;
            case SOLIB:
                SoLibrary soLibrary = DependencyConvertUtils.toSoLibrary(dependencyInfo);
                androidDependencyTree.getSoLibraries().add(soLibrary);
                break;
            case APK:
                ApkLibrary apkLibrary = DependencyConvertUtils.toApkLibrary(dependencyInfo);
                androidDependencyTree.getApkLibraries().add(apkLibrary);
                break;
            case AP:
                ApLibrary apLibrary = DependencyConvertUtils.toApLibrary(dependencyInfo);
                androidDependencyTree.getApLibraries().add(apLibrary);
                break;
            default:
                break;
        }
    }
    return androidDependencyTree;
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) ApLibrary(com.taobao.android.builder.dependency.model.ApLibrary) ApkLibrary(com.taobao.android.builder.dependency.model.ApkLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Example 9 with AndroidLibrary

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

the class MergeAwbResourceConfigAction method execute.

@Override
public void execute(MergeResources mergeResourcesTask) {
    VariantScope scope = variantContext.getScope();
    final BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();
    final AndroidConfig extension = scope.getGlobalScope().getExtension();
    //final VariantConfiguration variantConfig = variantData.getVariantConfiguration();
    mergeResourcesTask.setMinSdk(variantData.getVariantConfiguration().getMinSdkVersion().getApiLevel());
    mergeResourcesTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    mergeResourcesTask.setVariantName(scope.getVariantConfiguration().getFullName());
    GlobalScope globalScope = scope.getGlobalScope();
    mergeResourcesTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
    try {
        FieldUtils.writeField(mergeResourcesTask, "variantScope", scope, true);
    } catch (IllegalAccessException e) {
        throw new GradleException("exception", e);
    }
    // where blame is useful, and once for packaging where it is not.
    if (includeDependencies) {
        mergeResourcesTask.setBlameLogFolder(scope.getResourceBlameLogDir());
    } else {
    //            if (variantContext instanceof AppVariantContext) {
    //                mergeResourcesTask.setBlameLogFolder(((AppVariantContext) variantContext).getAwbBlameLogFolder(awbBundle));
    //            }
    }
    mergeResourcesTask.setProcess9Patch(process9Patch);
    mergeResourcesTask.setCrunchPng(extension.getAaptOptions().getCruncherEnabled());
    VectorDrawablesOptions vectorDrawablesOptions = variantData.getVariantConfiguration().getMergedFlavor().getVectorDrawables();
    Set<String> generatedDensities = vectorDrawablesOptions.getGeneratedDensities();
    mergeResourcesTask.setGeneratedDensities(Objects.firstNonNull(generatedDensities, Collections.<String>emptySet()));
    mergeResourcesTask.setDisableVectorDrawables(vectorDrawablesOptions.getUseSupportLibrary() || mergeResourcesTask.getGeneratedDensities().isEmpty());
    //mergeResourcesTask.setUseNewCruncher(extension.getAaptOptions().getUseNewCruncher());
    final boolean validateEnabled = AndroidGradleOptions.isResourceValidationEnabled(scope.getGlobalScope().getProject());
    mergeResourcesTask.setValidateEnabled(validateEnabled);
    ConventionMappingHelper.map(mergeResourcesTask, "inputResourceSets", new Callable<List<ResourceSet>>() {

        @Override
        public List<ResourceSet> call() throws Exception {
            List<ResourceSet> resourceSets = 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 resFolder = dependency.getResFolder();
                if (resFolder.isDirectory()) {
                    ResourceSet resourceSet = new ResourceSet(dependency.getFolder().getName(), true);
                    resourceSet.addSource(resFolder);
                    resourceSets.add(resourceSet);
                }
            }
            File awbResourceFolder = awbBundle.getResFolder();
            if (awbResourceFolder.isDirectory()) {
                ResourceSet resourceSet = new ResourceSet(awbBundle.getFolder().getName(), true);
                resourceSet.addSource(awbResourceFolder);
                resourceSets.add(resourceSet);
            }
            return resourceSets;
        }
    });
    mergeResourcesTask.setOutputDir(variantContext.getMergeResources(awbBundle));
    mergeResourcesTask.setGeneratedPngsOutputDir(variantContext.getPngsOutputDir(awbBundle));
//        if (variantContext instanceof AppVariantContext) {
//            AppVariantContext appVariantContext = (AppVariantContext) variantContext;
//            appVariantContext.getAwbMergeResourceTasks().put(awbBundle.getName(), mergeResourcesTask);
//        }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) ResourceSet(com.android.ide.common.res2.ResourceSet) AndroidConfig(com.android.build.gradle.AndroidConfig) GradleException(org.gradle.api.GradleException) VectorDrawablesOptions(com.android.builder.model.VectorDrawablesOptions) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleException(org.gradle.api.GradleException) List(java.util.List) File(java.io.File)

Example 10 with AndroidLibrary

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

the class MergeAwbManifests method getLibraryManifests.

/**
     * A synthetic input to allow gradle up-to-date checks to work.
     * <p>
     * Since List<ManifestDependencyImpl> can't be used directly, as @Nested doesn't work on lists,
     * this method gathers and returns the underlying manifest files.
     */
@SuppressWarnings("unused")
@InputFiles
List<File> getLibraryManifests() {
    List<? extends AndroidLibrary> libs = getLibraries();
    if (libs == null || libs.isEmpty()) {
        return Collections.emptyList();
    }
    List<File> files = Lists.newArrayListWithCapacity(libs.size() * 2);
    for (AndroidLibrary mdi : libs) {
        files.add(mdi.getManifest());
    }
    return files;
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile) InputFiles(org.gradle.api.tasks.InputFiles)

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