Gradle Transform 输出路径解析

本文详细解析了Android Gradle Transform任务的输出路径结构,包括transforms目录、productFlavor/buildType、jars/folders、OutputTypes和Scopes。路径主要由TransformOutputProvider的参数决定,例如Format决定了jars还是folders,types影响OutputTypes的值,而scopes则影响Scopes的数值。通过实例分析了自定义Transform Task、Proguard Task和dex Task的路径生成逻辑。
摘要由CSDN通过智能技术生成

目录

1、transforms路径下首先是各个Transform Task的名字所代表的路径

2、${productFlavor}/${buildType}

3、release后面是 jars 或 folders

1)自定的 Transform Task (StripAarTransform)

2)对于 Proguard Transform Task 来说

3)  对于dex Transform Task 来说

4、folders|jars 后面是 ${OutputTypes}

1)自定的 Transform Task (StripAarTransform)

2)对于 Proguard Transform Task 来说

3)对于dex Transform Task 来说

5、OutputTypes 后面是 ${Scopes}

1)自定的 Transform Task (StripAarTransform)

2)对于 Proguard Transform Task 来说

3)  对于dex Transform Task 来说


无意中注意到,Transform task 的输出路径,好奇,这么奇怪的路径是怎么生成的?

比如:

Proguard (task 为:transformClassesAndResourcesWithProguardForDebug、transformClassesAndResourcesWithProguardForRelease)的输出路径:

build/intermediates/transforms/proguard/debug/jars/3/1f/main.jar

build/intermediates/transforms/proguard/release/jars/3/1f/main.jar

 

先给个结论吧:

主要是由 TransformOutputProvider#getContentLocation(name, types, scopes, format) 中的参数决定的!

 

源码定义在:com.android.build.api.transform.TransformOutputProvider.java:

/**
 * The output of a transform.
 * <p>
 * There is no direct access to a location to write. Instead, Transforms can ask to get the
 * location for given scopes, content-types and a format.
 */
public interface TransformOutputProvider {
    /**
     * Delete all content. This is useful when running in non-incremental mode
     * @throws IOException
     */
    void deleteAll() throws IOException;
    /**
     * Returns the location of content for a given set of Scopes, Content Types, and Format.
     * <p>
     * If the format is {@link Format#DIRECTORY} then the result is the file location of the
     * directory.<br>
     * If the format is {@link Format#JAR} then the result is a file representing the jar to create.
     * <p>
     * Non of the directories or files are created by querying this method, and there is
     * no checks regarding the existence of content in this location.
     * <p>
     * In case of incremental processing of removed files, it is safe to query the method to get
     * the location of the files to removed.
     *
     * @param name a unique name for the content. For a given set of scopes/types/format it must
     *             be unique.
     * @param types the content types associated with this content.
     * @param scopes the scopes associated with this content.
     * @param format the format of the content.
     * @return the location of the content.
     */
    @NonNull
    File getContentLocation(@NonNull String name,
            @NonNull Set<QualifiedContent.ContentType> types,
            @NonNull Set<? super QualifiedContent.Scope> scopes,
            @NonNull Format format);
}

 

 

 

1、transforms路径下首先是各个Transform Task的名字所代表的路径

如:

transforms/dex

transforms/proguard

 

 

 

2、${productFlavor}/${buildType}

proguard下下面,紧接着的路径是:${productFlavor}/${buildType},没有productFlavor就省略,如:

transforms/proguard/qihoo/release/jars/3/1f/main.jar

transforms/proguard/qihoo/debug/jars/3/1f/main.jar

transforms/proguard/xiaomi/release/jars/3/1f/main.jar

transforms/proguard/xiaomi/debug/jars/3/1f/main.jar

 

 

3、release后面是 jars 或 folders

如:

release/folders

release/jars

如何确定是 jars 还是 folders?

 

先给结论:

jars 或 folders 是由 TransformOutputProvider#getContentLocation(name, types, scopes,

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值