Search in sources :

Example 36 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)

Example 37 with AndroidLibrary

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

the class PostProcessManifestTask method getLibManifestDepenendyMap.

public Multimap<String, File> getLibManifestDepenendyMap() {
    Multimap<String, File> maps = HashMultimap.create();
    List<? extends AndroidLibrary> libs = getAwbLibraries();
    if (libs == null || libs.isEmpty()) {
        return maps;
    }
    for (AndroidLibrary mdi : libs) {
        for (AndroidLibrary childLib : mdi.getLibraryDependencies()) {
            ((HashMultimap<String, File>) maps).put(mdi.getName(), childLib.getManifest());
        }
    }
    return maps;
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) HashMultimap(com.google.common.collect.HashMultimap)

Example 38 with AndroidLibrary

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

the class PostProcessManifestTask method getLibManifestMap.

public Map<String, File> getLibManifestMap() {
    Map<String, File> maps = Maps.newHashMap();
    List<? extends AndroidLibrary> libs = getAwbLibraries();
    if (libs == null || libs.isEmpty()) {
        return Collections.emptyMap();
    }
    for (AndroidLibrary mdi : libs) {
        ((HashMap<String, File>) maps).put(mdi.getName(), mdi.getManifest());
    }
    return maps;
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) HashMap(java.util.HashMap) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile)

Example 39 with AndroidLibrary

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

the class PreProcessManifestTask method addAwbManifest2Merge.

private void addAwbManifest2Merge() {
    AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
    for (final BaseVariantOutputData vod : appVariantContext.getVariantData().getOutputs()) {
        ManifestProcessorTask manifestProcessorTask = vod.manifestProcessorTask;
        Set<String> notMergedArtifacts = Sets.newHashSet();
        if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
            notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
        }
        if (manifestProcessorTask instanceof MergeManifests) {
            MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
            VariantScope variantScope = appVariantContext.getScope();
            GradleVariantConfiguration config = variantScope.getVariantConfiguration();
            AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
            if (null == dependencyTree) {
                throw new StopExecutionException("DependencyTree cannot be null!");
            }
            List<? extends AndroidLibrary> awbManifests = ManifestDependencyUtil.getManifestDependencies(dependencyTree.getAwbBundles(), notMergedArtifacts, getLogger());
            for (AndroidLibrary manifest : awbManifests) {
                getLogger().info("[MTLPlugin]Add manifest:" + manifest.getName() + ",path is:" + manifest.getManifest().getAbsolutePath());
            }
            //FIXME 不加这一步,每次的getibraries 都会从mapping里去重新计算
            mergeManifests.setLibraries(mergeManifests.getLibraries());
            mergeManifests.getLibraries().addAll(awbManifests);
        }
    }
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) MergeManifests(com.android.build.gradle.tasks.MergeManifests) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) ManifestProcessorTask(com.android.build.gradle.tasks.ManifestProcessorTask)

Example 40 with AndroidLibrary

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

the class PrepareAwoBundleTask method doFullTaskAction.

@TaskAction
public void doFullTaskAction() throws IOException {
    AwbBundle awbBundle = libVariantContext.getAwbBundle();
    prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
    List<SoLibrary> soLibraries = awbBundle.getSoLibraries();
    for (final SoLibrary soLibrary : soLibraries) {
        prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
    }
    List<? extends AndroidLibrary> aarBundles = awbBundle.getLibraryDependencies();
    for (final AndroidLibrary libraryDependency : aarBundles) {
        if (libraryDependency instanceof AarBundle) {
            AarBundle aarBundle = (AarBundle) libraryDependency;
            prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
        }
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) 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)

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