Search in sources :

Example 1 with SoLibrary

use of com.taobao.android.builder.dependency.model.SoLibrary in project atlas by alibaba.

the class CopyAwoSolibTask method doFullTaskAction.

@TaskAction
public void doFullTaskAction() {
    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }
    Set<String> removeSoFiles = new HashSet<String>();
    Set<String> supportAbis = new HashSet<String>();
    //为了兼容之前老的aar,awb格式
    File libJniFolder = new File(awbBundle.getFolder(), "libs");
    if (libJniFolder.exists() && libJniFolder.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    File libJniFolder2 = new File(awbBundle.getFolder(), "jni");
    if (libJniFolder2.exists() && libJniFolder2.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder2, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    File libJniFolder3 = new File(awbBundle.getFolder(), "jniLibs");
    if (libJniFolder3.exists() && libJniFolder3.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder3, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    List<? extends AndroidLibrary> deps = awbBundle.getLibraryDependencies();
    for (AndroidLibrary dep : deps) {
        File depJniFolder = dep.getJniFolder();
        if (depJniFolder.exists() && depJniFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(depJniFolder, outputDir, supportAbis, removeSoFiles, getILogger());
        }
        //为了兼容之前老的aar,awb格式
        File depLibsFolder = new File(dep.getFolder(), "libs");
        if (depLibsFolder.exists() && depLibsFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(depLibsFolder, outputDir, supportAbis, removeSoFiles, getILogger());
        }
    }
    List<SoLibrary> solibs = awbBundle.getSoLibraries();
    if (null != solibs) {
        for (SoLibrary solib : solibs) {
            File explodeFolder = solib.getFolder();
            if (!explodeFolder.exists()) {
                LibraryCache.unzipAar(solib.getSoLibFile(), explodeFolder, getProject());
            }
            if (explodeFolder.exists() && explodeFolder.isDirectory()) {
                NativeSoUtils.copyLocalNativeLibraries(explodeFolder, outputDir, supportAbis, removeSoFiles, getILogger());
            }
        }
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) File(java.io.File) HashSet(java.util.HashSet) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with SoLibrary

use of com.taobao.android.builder.dependency.model.SoLibrary 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 3 with SoLibrary

use of com.taobao.android.builder.dependency.model.SoLibrary in project atlas by alibaba.

the class DependencyConvertUtils method collectChildren.

/**
     * 收集子集合
     *
     * @param dependencyInfo
     * @param dependencies
     * @param jarDependencies
     * @param soLibraries
     */
private static void collectChildren(ResolvedDependencyInfo dependencyInfo, List<LibraryDependency> dependencies, Collection<JarDependency> jarDependencies, List<SoLibrary> soLibraries) {
    List<ResolvedDependencyInfo> children = dependencyInfo.getChildren();
    for (ResolvedDependencyInfo child : children) {
        switch(Type.getType(child.getType())) {
            case AAR:
                AarBundle aarBundle = toAarBundle(child, false);
                dependencies.add(aarBundle);
                collectChildren(child, dependencies, jarDependencies, soLibraries);
                break;
            case JAR:
                JarDependency jarInfo = toJarDependency(child, false);
                jarDependencies.add(jarInfo);
                collectChildren(child, dependencies, jarDependencies, soLibraries);
                break;
            case SOLIB:
                SoLibrary soLibrary = toSoLibrary(child);
                soLibraries.add(soLibrary);
                break;
            default:
                break;
        }
    }
}
Also used : JarDependency(com.android.builder.dependency.JarDependency) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Example 4 with SoLibrary

use of com.taobao.android.builder.dependency.model.SoLibrary in project atlas by alibaba.

the class DependencyConvertUtils method toSoLibrary.

/**
     * 转换为solibrary依赖
     *
     * @param resolvedDependencyInfo
     * @return
     */
public static SoLibrary toSoLibrary(ResolvedDependencyInfo resolvedDependencyInfo) {
    assertType(Type.SOLIB, resolvedDependencyInfo);
    ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact();
    SoLibrary soLibrary = new SoLibrary(convert(artifact), artifact.getFile(), resolvedDependencyInfo.getExplodedDir());
    return soLibrary;
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Example 5 with SoLibrary

use of com.taobao.android.builder.dependency.model.SoLibrary in project atlas by alibaba.

the class DependencyConvertUtils method toAarBundle.

/**
     * 将依赖类型转换为LibraryDependencyImpl
     *
     * @param resolvedDependencyInfo
     * @return
     */
private static AarBundle toAarBundle(ResolvedDependencyInfo resolvedDependencyInfo, boolean containChild) {
    assertType(Type.AAR, resolvedDependencyInfo);
    List<LibraryDependency> dependencies = Lists.newArrayList();
    Collection<JarDependency> jarDependencies = Lists.newArrayList();
    List<SoLibrary> soLibraries = Lists.newArrayList();
    if (containChild) {
        collectChildren(resolvedDependencyInfo, dependencies, jarDependencies, soLibraries);
    }
    AarBundle aarBundle = new AarBundle(resolvedDependencyInfo.getResolvedArtifact().getFile(), resolvedDependencyInfo.getExplodedDir(), dependencies, jarDependencies, resolvedDependencyInfo.getGroup() + "-" + resolvedDependencyInfo.getName(), resolvedDependencyInfo.getVariantName(), resolvedDependencyInfo.getGradlePath(), null, convert(resolvedDependencyInfo.getResolvedArtifact()));
    aarBundle.setSoLibraries(soLibraries);
    return aarBundle;
}
Also used : JarDependency(com.android.builder.dependency.JarDependency) LibraryDependency(com.android.builder.dependency.LibraryDependency) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Aggregations

SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)11 AarBundle (com.taobao.android.builder.dependency.model.AarBundle)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)6 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)5 TaskAction (org.gradle.api.tasks.TaskAction)5 JarDependency (com.android.builder.dependency.JarDependency)3 JavaLibrary (com.android.builder.model.JavaLibrary)3 LibraryDependency (com.android.builder.dependency.LibraryDependency)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 Multimap (com.google.common.collect.Multimap)1 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)1 ApLibrary (com.taobao.android.builder.dependency.model.ApLibrary)1 ApkLibrary (com.taobao.android.builder.dependency.model.ApkLibrary)1 DependencyJson (com.taobao.android.builder.dependency.output.DependencyJson)1 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)1 HashSet (java.util.HashSet)1 List (java.util.List)1