Search in sources :

Example 6 with SoLibrary

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

the class DependencyConvertUtils method toAwbBundle.

public static AwbBundle toAwbBundle(ResolvedDependencyInfo resolvedDependencyInfo) {
    assertType(Type.AWB, resolvedDependencyInfo);
    List<LibraryDependency> dependencies = Lists.newArrayList();
    Collection<JarDependency> jarDependencies = Lists.newArrayList();
    List<SoLibrary> soLibraries = Lists.newArrayList();
    collectChildren(resolvedDependencyInfo, dependencies, jarDependencies, soLibraries);
    AwbBundle awbBundle = new AwbBundle(resolvedDependencyInfo.getResolvedArtifact().getFile(), resolvedDependencyInfo.getExplodedDir(), dependencies, jarDependencies, resolvedDependencyInfo.getGroup() + "-" + resolvedDependencyInfo.getName(), resolvedDependencyInfo.getVariantName(), resolvedDependencyInfo.getGradlePath(), null, convert(resolvedDependencyInfo.getResolvedArtifact()));
    awbBundle.setSoLibraries(soLibraries);
    return awbBundle;
}
Also used : JarDependency(com.android.builder.dependency.JarDependency) LibraryDependency(com.android.builder.dependency.LibraryDependency) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 7 with SoLibrary

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

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

the class PrepareAwbTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException, IOException, DocumentException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    Set<SoLibrary> soLibraries = androidDependencyTree.getALLSoLibDependencies();
    for (final SoLibrary soLibrary : soLibraries) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
    List<AwbBundle> awbBundles = androidDependencyTree.getAwbBundles();
    for (final AwbBundle awbBundle : awbBundles) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
    Set<AarBundle> aarBundles = androidDependencyTree.getALLAarDependencies();
    for (final AarBundle aarBundle : aarBundles) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ArrayList(java.util.ArrayList) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 9 with SoLibrary

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

the class AwoDependency method parseDependency.

public void parseDependency(AndroidDependencyTree libDependencyTree, AwbBundle awbBundle) {
    List<SoLibrary> soLibraries = new ArrayList<SoLibrary>();
    for (SoLibrary soLibrary : libDependencyTree.getSoLibraries()) {
        if (isCompileDependency(soLibrary.getResolvedCoordinates())) {
            soLibraries.add(soLibrary);
        }
    }
    List aarBundles = new ArrayList<>();
    for (AarBundle aarBundle : libDependencyTree.getAarBundles()) {
        if (isCompileDependency(aarBundle.getResolvedCoordinates())) {
            aarBundles.add(aarBundle);
        }
    }
    List jarInfos = new ArrayList<JavaLibrary>();
    for (JavaLibrary jarInfo : libDependencyTree.getJars()) {
        if (isCompileDependency(jarInfo.getResolvedCoordinates())) {
            jarInfos.add(jarInfo);
        }
    }
    awbBundle.getSoLibraries().addAll(soLibraries);
    awbBundle.getLibraryDependencies().addAll(aarBundles);
    awbBundle.getJavaDependencies().addAll(jarInfos);
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) ArrayList(java.util.ArrayList) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) ArrayList(java.util.ArrayList) List(java.util.List) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Example 10 with SoLibrary

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

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