Search in sources :

Example 66 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class PrepareMainDexJarsTask method doFullTaskAction.

@TaskAction
public void doFullTaskAction() {
    AndroidDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(this.getVariantName());
    if (null == libDependencyTree) {
        throw new GradleException("The libDependencyTree is null!");
    }
    List<File> jarList = new AwoDependency(libVariantContext).getDependencyJar(libDependencyTree);
    libVariantContext.setJarDexList(jarList);
}
Also used : AwoDependency(com.taobao.android.builder.tasks.awo.utils.AwoDependency) GradleException(org.gradle.api.GradleException) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 67 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class PrepareAaptTask method doExecute.

//MergeResources mergeResources;
@TaskAction
public void doExecute() {
    AaptOptions aaptOptions = processAndroidResources.getAaptOptions();
    if (null == aaptOptions) {
        aaptOptions = new AaptOptions();
    }
    if (null == aaptOptions.getAdditionalParameters()) {
        aaptOptions.setAdditionalParameters(new ArrayList<String>());
    }
    if (!appVariantContext.getAtlasExtension().getTBuildConfig().getAaptConstantId()) {
        aaptOptions.getAdditionalParameters().add("--non-constant-id");
    }
    processAndroidResources.setAndroidBuilder(getBuilder());
    processAndroidResources.setAaptOptions(aaptOptions);
    ApContext apContext = appVariantContext.apContext;
    if (null != apContext && apContext.getBaseApk().exists()) {
        File baseApk = appVariantContext.apContext.getBaseApk();
        //需要增加-b参数
        if (!aaptOptions.getAdditionalParameters().contains("-B")) {
            aaptOptions.getAdditionalParameters().add("-B");
            aaptOptions.getAdditionalParameters().add(baseApk.getAbsolutePath());
        }
    //AndroidManifest文件不能有修改OR在patch的时候忽略,目前选择在patch的时候忽略
    }
//TODO update merge resource
//mergeResources.setAndroidBuilder(AtlasBuildContext.androidBuilder);
}
Also used : ApContext(com.android.build.gradle.internal.api.ApContext) AaptOptions(com.android.build.gradle.internal.dsl.AaptOptions) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 68 with TaskAction

use of org.gradle.api.tasks.TaskAction 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 69 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class PrepareAPTask method generate.

/**
     * 生成so的目录
     */
@TaskAction
void generate() {
    Project project = getProject();
    File apBaseFile = null;
    if (null != apContext.getApFile() && apContext.getApFile().exists()) {
        apBaseFile = apContext.getApFile();
    } else if (StringUtils.isNotBlank(apContext.getApDependency())) {
        Dependency dependency = project.getDependencies().create(apContext.getApDependency());
        Configuration configuration = project.getConfigurations().detachedConfiguration(dependency);
        configuration.setTransitive(false);
        for (File file : configuration.getFiles()) {
            if (file.getName().endsWith(".ap")) {
                apBaseFile = file;
                break;
            }
        }
    }
    if (null != apBaseFile && apBaseFile.exists()) {
        File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-ap" + "/");
        ZipUtils.unzip(apBaseFile, explodedDir.getAbsolutePath());
        apContext.setApExploredFolder(explodedDir);
        apContext.setBaseApk(new File(explodedDir, "android.apk"));
    }
}
Also used : Project(org.gradle.api.Project) Configuration(org.gradle.api.artifacts.Configuration) Dependency(org.gradle.api.artifacts.Dependency) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 70 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class ProcessResAwbsTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    final VariantOutputScope outputScope = appVariantOutputContext.getOutputScope();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                File symbolLocation = new File(outputScope.getGlobalScope().getIntermediatesDir(), "awb-symbols/" + outputScope.getVariantScope().getVariantConfiguration().getDirName() + "/" + awbBundle.getName());
                //把资源写入ap中,给debug用
                if ("debug".equals(appVariantOutputContext.getVariantContext().getBaseVariantData().getName())) {
                    appVariantOutputContext.appBuildInfo.getOtherFilesMap().put("awo/" + awbBundle.getPackageName() + ".R.txt", new File(symbolLocation, "R.txt"));
                }
                ProcessAwbAndroidResources.ConfigAction configAction = new ProcessAwbAndroidResources.ConfigAction(outputScope, symbolLocation, true, awbBundle, (AtlasBuilder) getBuilder(), appVariantOutputContext);
                ProcessAwbAndroidResources processAwbAndroidResources = TaskCreater.create(getProject(), configAction.getName(), configAction.getType());
                configAction.execute(processAwbAndroidResources);
                processAwbAndroidResources.execute();
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) VariantOutputScope(com.android.build.gradle.internal.scope.VariantOutputScope) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AtlasBuilder(com.android.builder.core.AtlasBuilder) 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

TaskAction (org.gradle.api.tasks.TaskAction)92 File (java.io.File)40 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)22 GradleException (org.gradle.api.GradleException)15 ArrayList (java.util.ArrayList)11 InputFile (org.gradle.api.tasks.InputFile)11 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)10 OutputFile (org.gradle.api.tasks.OutputFile)10 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)9 IOException (java.io.IOException)8 Project (org.gradle.api.Project)8 WorkResult (org.gradle.api.tasks.WorkResult)8 BuildOperationLogger (org.gradle.internal.operations.logging.BuildOperationLogger)8 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)7 InvalidUserDataException (org.gradle.api.InvalidUserDataException)7 HashSet (java.util.HashSet)6 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)5 AndroidLibrary (com.android.builder.model.AndroidLibrary)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4