Search in sources :

Example 1 with FileCacheException

use of com.taobao.android.builder.tools.cache.FileCacheException in project atlas by alibaba.

the class AtlasBuilder method preDexLibrary.

public void preDexLibrary(@NonNull File inputFile, @NonNull File outFile, boolean multiDex, @NonNull DexOptions dexOptions, @NonNull ProcessOutputHandler processOutputHandler) throws IOException, InterruptedException, ProcessException {
    if (!atlasExtension.getTBuildConfig().isDexCacheEnabled() || multiDex) {
        super.preDexLibrary(inputFile, outFile, multiDex, dexOptions, processOutputHandler, 14);
        return;
    }
    String md5 = "";
    File dexFile = new File(outFile, "classes.dex");
    if (!inputFile.getName().startsWith("combined") && !(inputFile.getName().startsWith("main") && inputFile.getName().endsWith("jar")) && inputFile.isFile()) {
        if (inputFile.isFile()) {
            md5 = MD5Util.getFileMD5(inputFile);
        } else if (inputFile.isDirectory()) {
            md5 = MD5Util.getFileMd5(FileUtils.listFiles(inputFile, new String[] { "class" }, true));
        }
        // TODO md5 with other
        if (StringUtils.isNotEmpty(md5)) {
            String other = "" + dexOptions.getAdditionalParameters().contains("--useMyDex") + dexOptions.getJumboMode() + dexOptions.getKeepRuntimeAnnotatedClasses();
            try {
                md5 = MD5Util.getMD5(other + md5);
            } catch (Exception e) {
                throw new GradleException(e.getMessage(), e);
            }
            try {
                FileCacheCenter.fetchFile(PRE_DEXCACHE_TYPE, md5, false, atlasExtension.getTBuildConfig().isDexNetworkCacheEnabled(), dexFile);
            } catch (FileCacheException e) {
                sLogger.error(e.getMessage(), e);
            }
            if (dexFile.exists() && dexFile.length() > 0) {
                sLogger.info("[mtldex] hit cache dex for {} , {}", inputFile.getAbsolutePath(), dexFile.getAbsolutePath());
                return;
            } else {
                sLogger.info("[mtldex] discache dex for {}", inputFile.getAbsolutePath());
            }
        }
    } else {
    // R Too much, you need to start multi-dex
    }
    multiDex = false;
    dexFile.delete();
    // todo  Set the dexOptions
    DefaultDexOptions defaultDexOptions = DefaultDexOptions.copyOf(dexOptions);
    if (!multiDex) {
        defaultDexOptions.setJavaMaxHeapSize("500m");
        defaultDexOptions.setDexInProcess(true);
        defaultDexOptions.getAdditionalParameters().remove("--multi-dex");
    }
    sLogger.info("[mtldex] pre dex for {} {}", inputFile.getAbsolutePath(), outFile.getAbsolutePath());
    super.preDexLibrary(inputFile, outFile, multiDex, defaultDexOptions, processOutputHandler, 14);
    if (multiDex) {
        return;
    }
    if (!dexFile.exists() || dexFile.length() == 0) {
        sLogger.warn("dex failed " + dexFile.getAbsolutePath() + "->" + inputFile.getAbsolutePath());
        return;
    }
    sLogger.warn("dex success " + dexFile.getAbsolutePath() + "->" + inputFile.getAbsolutePath());
    if (StringUtils.isNotEmpty(md5) && dexFile.exists()) {
        try {
            FileCacheCenter.cacheFile(PRE_DEXCACHE_TYPE, md5, dexFile, AtlasBuildContext.sBuilderAdapter.pushCacheToNetwork && atlasExtension.getTBuildConfig().isDexNetworkCacheEnabled());
        } catch (FileCacheException e) {
            sLogger.error(e.getMessage(), e);
        }
    }
}
Also used : GradleException(org.gradle.api.GradleException) FileCacheException(com.taobao.android.builder.tools.cache.FileCacheException) File(java.io.File) FileCacheException(com.taobao.android.builder.tools.cache.FileCacheException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException)

Aggregations

FileCacheException (com.taobao.android.builder.tools.cache.FileCacheException)1 File (java.io.File)1 IOException (java.io.IOException)1 GradleException (org.gradle.api.GradleException)1