Search in sources :

Example 1 with TBuildConfig

use of com.taobao.android.builder.extension.TBuildConfig in project atlas by alibaba.

the class AtlasConfigurationHelper method updateExtensionAfterEvaluate.

// public void hookAtlasDependencyManager() {
// 
// try {
// this.appPluginHook.replaceTaskManager();
// } catch (Exception e) {
// throw new GradleException(e.getMessage(), e);
// }
// }
/**
 * Set the necessary default parameters for atlas
 */
public void updateExtensionAfterEvaluate() {
    if (atlasExtension.isAtlasEnabled() && !(project.getPlugins().hasPlugin(FeaturePlugin.class) || project.getPlugins().hasPlugin(AtlasFeaturePlugin.class))) {
        TBuildConfig tBuildConfig = atlasExtension.getTBuildConfig();
        // tBuildConfig.setAaptConstantId(false);
        // tBuildConfig.setClassInject(true);
        // tBuildConfig.setCreateAP(true);
        tBuildConfig.setUseCustomAapt(true);
        atlasExtension.getManifestOptions().setAddMultiDexMetaData(true);
        // atlasExtension.getManifestOptions().setAddBundleLocation(true);
        atlasExtension.getManifestOptions().setReplaceApplication(true);
    } else {
        atlasExtension.getManifestOptions().setReplaceApplication(false);
    }
}
Also used : TBuildConfig(com.taobao.android.builder.extension.TBuildConfig)

Example 2 with TBuildConfig

use of com.taobao.android.builder.extension.TBuildConfig in project atlas by alibaba.

the class PreparePackageIdsTask method generate.

/**
 * packageid The range is 30 - 127
 */
@TaskAction
void generate() throws IOException {
    TBuildConfig tBuildConfig = appVariantContext.getAtlasExtension().getTBuildConfig();
    File packageIdFile = tBuildConfig.getPackageIdFile();
    File apPackageIdFile = appVariantContext.apContext.getPackageIdFile();
    boolean isAutoPackageId = tBuildConfig.isAutoPackageId();
    int minPackageId = tBuildConfig.getMinPackageId();
    Map<String, String> autoConfigMap = new HashMap<String, String>();
    if (null != apPackageIdFile && apPackageIdFile.exists()) {
        autoConfigMap.putAll(loadPackageIdProperties(apPackageIdFile));
    } else if (null != packageIdFile && packageIdFile.exists()) {
        autoConfigMap.putAll(loadPackageIdProperties(packageIdFile));
    }
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
        if (autoConfigMap.containsKey(key)) {
            continue;
        }
        File customPackageIDFile = new File(awbBundle.getAndroidLibrary().getFolder(), "customPackageID.txt");
        String packageId = getCustomPackageId(customPackageIDFile);
        if (StringUtils.isNotEmpty(packageId)) {
            autoConfigMap.put(key, packageId);
        } else {
            autoConfigMap.put(key, "");
        }
    }
    if (isAutoPackageId && autoConfigMap.containsValue("")) {
        // Automatic allocation of autoConfig
        List<String> keys = new ArrayList<String>(autoConfigMap.keySet());
        Collections.sort(keys);
        for (String key : keys) {
            if ("".equals(autoConfigMap.get(key))) {
                for (int i = minPackageId; i < /*=*/
                127; i++) {
                    if (!autoConfigMap.values().contains(String.valueOf(i))) {
                        autoConfigMap.put(key, String.valueOf(i));
                        break;
                    }
                }
            }
        }
    }
    AtlasBuildContext.customPackageIdMaps = autoConfigMap;
    // wite package Id file
    File outPkgFile = new File(getProject().getBuildDir(), "outputs/packageIdFile.properties");
    writeProperties(autoConfigMap, outPkgFile);
    appBuildInfo.setPackageIdFile(outPkgFile);
    // check value
    if (autoConfigMap.containsValue("")) {
        getLogger().error(JSON.toJSONString(autoConfigMap, true));
        throw new GradleException("packageId Error configuration, please check");
    }
    if (autoConfigMap.size() != new HashSet(autoConfigMap.values()).size()) {
        // getLogger().error(JSON.toJSONString(autoConfigMap, true));
        Map<String, PackageIdItem> idItemMap = new HashMap<String, PackageIdItem>();
        for (String key : autoConfigMap.keySet()) {
            String customPackageId = autoConfigMap.get(key);
            PackageIdItem packageIdItem = idItemMap.get(customPackageId);
            if (null == packageIdItem) {
                String[] split = customPackageId.split("\\.");
                packageIdItem = new PackageIdItem();
                packageIdItem.packageId = Integer.valueOf(split[0]);
                if (split.length > 1) {
                    packageIdItem.typeIdOffset = Integer.valueOf(split[1]);
                }
                idItemMap.put(customPackageId, packageIdItem);
            }
            packageIdItem.bundles.add(key);
        }
        Collection<PackageIdItem> collection = idItemMap.values();
        List<PackageIdItem> packageList = new ArrayList<PackageIdItem>(collection);
        Collections.sort(packageList, new Comparator<PackageIdItem>() {

            @Override
            public int compare(PackageIdItem o1, PackageIdItem o2) {
                return o1.packageId - o2.packageId;
            }
        });
        getLogger().error(JSON.toJSONString(packageList, true));
        throw new GradleException("packageId Configuration error, duplicate, please check");
    }
    // check if packageID is not used
    Map<String, String> autoConfigMap2 = new HashMap<>(autoConfigMap);
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
        autoConfigMap2.remove(key);
    }
    if (autoConfigMap2.size() > 0) {
        File outPkgFile2 = new File(getProject().getBuildDir(), "outputs/warning-unusedPackageIdFile.properties");
        writeProperties(autoConfigMap2, outPkgFile2);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TBuildConfig(com.taobao.android.builder.extension.TBuildConfig) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) GradleException(org.gradle.api.GradleException) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) HashSet(java.util.HashSet) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with TBuildConfig

use of com.taobao.android.builder.extension.TBuildConfig in project atlas by alibaba.

the class MainDexLister method getMainDexList.

public List<String> getMainDexList(Collection<File> files, File mainDexListFile) {
    GradleVariantConfiguration config = appVariantContext.getVariantConfiguration();
    Set<String> mainDexList = new HashSet<String>();
    // Confusion of the map
    // Map<String, String> classMap = getClassObfMap(config);
    Collection<BaseVariantOutput> collection = appVariantContext.getVariantOutputData();
    File manifest = com.android.utils.FileUtils.join(collection.iterator().next().getProcessManifest().getManifestOutputDirectory(), new String[] { collection.iterator().next().getDirName(), "AndroidManifest.xml" });
    if (appVariantContext.getScope().getInstantRunBuildContext().isInInstantRunMode()) {
        manifest = com.android.utils.FileUtils.join(collection.iterator().next().getProcessManifest().getInstantRunManifestOutputDirectory(), new String[] { collection.iterator().next().getDirName(), "AndroidManifest.xml" });
    }
    String applicationName = ManifestFileUtils.getApplicationName(manifest);
    ClassPool classPool = new ClassPool();
    try {
        for (File file : files) {
            if (file.isFile()) {
                classPool.insertClassPath(file.getAbsolutePath());
            } else {
                classPool.appendClassPath(file.getAbsolutePath());
            }
        }
    } catch (NotFoundException e) {
        throw new GradleException(e.getMessage(), e);
    }
    TBuildConfig tBuildConfig = appVariantContext.getAtlasExtension().getTBuildConfig();
    HashSet handleList = new HashSet<String>();
    Set<String> headClasses = new LinkedHashSet<>();
    headClasses.add(applicationName);
    headClasses.add("android.taobao.atlas.bridge.BridgeApplicationDelegate");
    headClasses.addAll(multiDexConfig.getFirstDexClasses());
    List<String> maindexListClazz = new ArrayList<String>();
    String preLaunchStr = tBuildConfig.getPreLaunch();
    if (!org.apache.commons.lang3.StringUtils.isEmpty(preLaunchStr)) {
        String[] launchArray = preLaunchStr.split("\\|");
        if (launchArray.length > 0) {
            for (String launchItem : launchArray) {
                String[] launchInfo = launchItem.split(":");
                String clazzName = launchInfo[0];
                headClasses.add(clazzName);
            }
        }
    }
    for (String clazz : headClasses) {
        clazz = clazz.replaceAll("\\.", "/") + ".class";
        maindexListClazz.add(clazz);
    }
    for (String headClass : headClasses) {
        addRefClazz(classPool, headClass, mainDexList, handleList, "");
    }
    // get manifest
    for (String newLine : mainDexList) {
        newLine = newLine.replaceAll("\\.", "/") + ".class";
        maindexListClazz.add(newLine);
    }
    for (String className : headClasses) {
        className = className.replaceAll("\\.", "/") + ".class";
        maindexListClazz.add(className);
    }
    if (multiDexConfig.getMainDexListCount() != 0) {
        maindexListClazz = maindexListClazz.subList(0, multiDexConfig.getMainDexListCount());
    }
    try {
        FileUtils.writeLines(mainDexListFile, maindexListClazz);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return maindexListClazz;
}
Also used : ClassPool(javassist.ClassPool) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) NotFoundException(javassist.NotFoundException) TBuildConfig(com.taobao.android.builder.extension.TBuildConfig) IOException(java.io.IOException) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) GradleException(org.gradle.api.GradleException) File(java.io.File)

Aggregations

TBuildConfig (com.taobao.android.builder.extension.TBuildConfig)3 File (java.io.File)2 GradleException (org.gradle.api.GradleException)2 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)1 GradleVariantConfiguration (com.android.build.gradle.internal.core.GradleVariantConfiguration)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ClassPool (javassist.ClassPool)1 NotFoundException (javassist.NotFoundException)1 TaskAction (org.gradle.api.tasks.TaskAction)1