复制并重命名从Gradle Android生成的AAR

az31mfrm  于 2023-03-30  发布在  Android
关注(0)|答案(1)|浏览(176)

在我的库模块,我想复制和重命名的aar文件到不同的路径下面的代码使用

ext {
    version = 'P-1.1.6'
    name = 'Player'
}
defaultConfig {
    missingDimensionStrategy "exoplayerversion", "Exo_2_13_3", "Exo_2_18_1"
    missingDimensionStrategy "playserviceversion", "PlayService_16_0_0", "PlayService_21_0_1"
    buildConfigField "String", "LIBRARY_VERSION", "\"${version}\""
}
libraryVariants.all { variant ->
    variant.outputs.all { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.aar')) {
            if (outputFile.name.contains("debug"))
                outputFileName = new File("../../../../releases/${version}", "${name}-${version}-debug.aar")
            else outputFileName = new File("../../../../releases/${version}", "${name}-${version}-release.aar")
        }
        variant.assemble.doLast {
            if (variant.mappingFile != null) {
                copy {
                    from variant.mappingFile
                    into outputFile.parent
                    rename { String fileName ->
                        "../../../../releases/${version}/mapping.txt"
                    }
                }
            }
        }
    }
}

正在复制aar文件,但名称不正确,我得到的aar名称为Exo_2_18_1-PlayService_16_0_0-debug-P-1.1.6-debug.aar,而它应该是Player-P-1.1.6-debug.aar

but5z9lq

but5z9lq1#

必须使用project.name

outputFileName = new File("../../../../releases/${version}", "${project.name}-${version}-debug.aar")

相关问题