Search in sources :

Example 56 with AndroidLibrary

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

the class StandardizeLibManifestTask method preProcess.

@TaskAction
public void preProcess() throws IOException, DocumentException, InterruptedException {
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantName());
    androidLibraries = dependencyTree.getAllAndroidLibrarys();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("StandardizeLibManifestTask", getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    ManifestInfo mainManifestFileObject = getManifestFileObject(mainManifestFile);
    appVariantContext.getModifyManifestDir().mkdirs();
    for (AndroidLibrary androidLibrary : androidLibraries) {
        File file = androidLibrary.getManifest();
        if (!file.exists()) {
            getLogger().error(androidLibrary.getResolvedCoordinates().toString() + " not has manifest : " + file.getAbsolutePath());
            return;
        }
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    File modifyManifest = appVariantContext.getModifyManifest(androidLibrary);
                    // getLogger().error(file.getAbsolutePath() + " -> " + modifyManifest
                    // .getAbsolutePath());
                    ManifestFileUtils.updatePreProcessManifestFile(modifyManifest, file, mainManifestFileObject, appVariantContext.getAtlasExtension().getTBuildConfig().isUpdateSdkVersion(), appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental());
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("preprocess manifest failed " + file.getAbsolutePath(), e);
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) ManifestInfo(com.taobao.android.builder.tools.manifest.ManifestInfo) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)

Example 57 with AndroidLibrary

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

the class ProcessAwbAndroidResources method doFullTaskAction.

@Override
protected void doFullTaskAction() throws IOException {
    File srcOut = getSourceOutputDir();
    aaptGeneration = AaptGeneration.fromProjectOptions(appVariantContext.getScope().getGlobalScope().getProjectOptions());
    if (srcOut != null) {
        // FileUtils.emptyFolder(srcOut);
        srcOut.delete();
        srcOut.mkdirs();
    }
    getTextSymbolOutputDir().mkdirs();
    getPackageOutputFile().getParentFile().mkdirs();
    @Nullable File resOutBaseNameFile = getPackageOutputFile();
    // If are in instant run mode and we have an instant run enabled manifest
    File instantRunManifest = getInstantRunManifestFile();
    File manifestFileToPackage = instantRunBuildContext.isInInstantRunMode() && instantRunManifest != null && instantRunManifest.exists() ? instantRunManifest : getManifestFile();
    // Add additional parameters required for the awb module to compile
    Set<File> libraries = new HashSet<>();
    for (AndroidLibrary androidLibrary : getLibraries()) {
        if (androidLibrary.getSymbolFile().exists()) {
            if (androidLibrary.getManifest().exists() && androidLibrary.getSymbolFile().exists()) {
                File libraryRtxt = androidLibrary.getSymbolFile();
                File awbPackageR = new File(libraryRtxt.getParentFile(), "package-aware-r.txt");
                SymbolIo.writeSymbolTableWithPackage(libraryRtxt.toPath(), androidLibrary.getManifest().toPath(), awbPackageR.toPath());
                libraries.add(awbPackageR);
            }
        }
    }
    // libraries.addAll(mainDexSymbolFileCollection.getFiles());
    addAaptOptions(aaptGeneration);
    AaptPackageConfig.Builder aaptPackageCommandBuilder = new AaptPackageConfig.Builder().setManifestFile(manifestFileToPackage).setOptions(DslAdaptersKt.convert(getAaptOptions())).setResourceDir(getResDir()).setLibrarySymbolTableFiles(libraries).setCustomPackageForR(getPackageForR()).setSourceOutputDir(srcOut).setSymbolOutputDir(getTextSymbolOutputDir()).setResourceOutputApk(resOutBaseNameFile).setProguardOutputFile(getProguardOutputFile()).setVariantType(getType()).setDebuggable(debuggable).setResourceConfigs(getResourceConfigs()).setSplits(getSplits()).setPreferredDensity(getPreferredDensity()).setPseudoLocalize(getPseudoLocalesEnabled()).setListResourceFiles(aaptGeneration == AaptGeneration.AAPT_V2);
    // .setPackageId(Integer.valueOf(getCustomPackageId()));
    @NonNull AndroidBuilder builder = getBuilder();
    Aapt aapt = makeAapt();
    try {
        if (builder instanceof AtlasBuilder) {
            ((AtlasBuilder) builder).processAwbResources(aapt, aaptPackageCommandBuilder, getMainSymbolFile(), awbBundle.getAndroidLibrary().getSymbolFile(), appVariantContext.getVariantData().getApplicationId());
        } else {
            builder.processResources(aapt, aaptPackageCommandBuilder);
        }
        if (resOutBaseNameFile != null) {
            if (instantRunBuildContext.isInInstantRunMode()) {
                instantRunBuildContext.addChangedFile(FileType.RESOURCES, resOutBaseNameFile);
                // get the new manifest file CRC
                JarFile jarFile = new JarFile(resOutBaseNameFile);
                String currentIterationCRC = null;
                try {
                    ZipEntry entry = jarFile.getEntry(SdkConstants.ANDROID_MANIFEST_XML);
                    if (entry != null) {
                        currentIterationCRC = String.valueOf(entry.getCrc());
                    }
                } finally {
                    jarFile.close();
                }
                // check the manifest file binary format.
                File crcFile = new File(instantRunSupportDir, "manifest.crc");
                if (crcFile.exists() && currentIterationCRC != null) {
                    // compare its content with the new binary file crc.
                    String previousIterationCRC = Files.readFirstLine(crcFile, Charsets.UTF_8);
                    if (!currentIterationCRC.equals(previousIterationCRC)) {
                        instantRunBuildContext.close();
                    // instantRunBuildContext.setVerifierResult(InstantRunVerifierStatus
                    // .BINARY_MANIFEST_FILE_CHANGE);
                    }
                }
                // write the new manifest file CRC.
                Files.createParentDirs(crcFile);
                Files.write(currentIterationCRC, crcFile, Charsets.UTF_8);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new GradleException("process res exception", e);
    }
}
Also used : AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) ZipEntry(java.util.zip.ZipEntry) JarFile(java.util.jar.JarFile) AaptPackageConfig(com.android.builder.internal.aapt.AaptPackageConfig) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) AndroidLibrary(com.android.builder.model.AndroidLibrary) NonNull(com.android.annotations.NonNull) GradleException(org.gradle.api.GradleException) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) Aapt(com.android.builder.internal.aapt.Aapt) JarFile(java.util.jar.JarFile) File(java.io.File) Nullable(com.android.annotations.Nullable)

Example 58 with AndroidLibrary

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

the class AtlasDepTreeParser method check.

private void check(AtlasDependencyTree atlasDependencyTree) {
    Map<String, List<String>> dependeys = new HashMap<>();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        String gav = awbBundle.getAndroidLibrary().getResolvedCoordinates().toString();
        for (AndroidLibrary androidLibrary : awbBundle.getAndroidLibraries()) {
            addValuetoList(dependeys, gav, androidLibrary.getResolvedCoordinates().toString());
        }
        for (JavaLibrary javaLibrary : awbBundle.getJavaLibraries()) {
            addValuetoList(dependeys, gav, javaLibrary.getResolvedCoordinates().toString());
        }
        for (SoLibrary soLibrary : awbBundle.getSoLibraries()) {
            addValuetoList(dependeys, gav, soLibrary.getResolvedCoordinates().toString());
        }
    }
    List<String> warnings = new ArrayList<>();
    for (String key : dependeys.keySet()) {
        List<String> values = dependeys.get(key);
        if (values.size() > 1) {
            String msg = key + ":" + StringUtils.join(values, ",");
            warnings.add(msg);
            logger.warning(msg);
        }
    }
    if (warnings.size() > 0) {
        logger.warning(JSON.toJSONString(atlasDependencyTree.getDependencyJson(), true));
        throw new GradleException("decencyconflict : " + StringUtils.join(warnings, "\r\n"));
    }
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleException(org.gradle.api.GradleException) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary)

Example 59 with AndroidLibrary

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

the class AwbBundle method getLibraryJars.

/**
 * Get all the associated jars
 *
 * @return
 */
public List<File> getLibraryJars() {
    List<File> jars = Lists.newArrayList();
    jars.add(androidLibrary.getJarFile());
    Collection<File> localJars = androidLibrary.getLocalJars();
    if (null != localJars) {
        jars.addAll(localJars);
    }
    if (null != androidLibraries) {
        for (AndroidLibrary aarBundle : androidLibraries) {
            if (aarBundle.getJarFile().exists()) {
                jars.add(aarBundle.getJarFile());
            }
            jars.addAll(aarBundle.getLocalJars());
        }
    }
    if (null != javaLibraries) {
        for (JavaLibrary javaLibrary : javaLibraries) {
            if (javaLibrary.getJarFile().exists()) {
                jars.add(javaLibrary.getJarFile());
            }
        }
    }
    return jars;
}
Also used : JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) File(java.io.File)

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