安卓AS自定义打包路径报错

升级as和gradle版本后,报错了

A problem was found with the configuration of task ':app:createTongyongReleaseApkListingFileRedirect' (type 'ListingFileRedirectTask').
  - In plugin 'com.android.internal.version-check' type 'com.android.build.gradle.internal.tasks.ListingFileRedirectTask' property 'listingFile' specifies file 'D:\项目地址\app\tongyong\release\output-metadata.json' which doesn't exist.

因为自定义了输出目录,output-metadata.json文件找不到了。

原来的代码

android.applicationVariants.all { variant ->
        variant.outputs.all {
            def aid = variant.applicationId.split("\\.")
            def name = aid[aid.length - 1]
            def buildEnv = env
            def buildType = variant.buildType.name
            def abi = getFilter(com.android.build.OutputFile.ABI)
            if (abi == null) abi = "all"
            def version = variant.versionName
            def versionCode = variant.versionCode
            def date = new Date()
            def formattedDate = date.format('yyyyMMdd_HHmm')
            outputFileName = "${name}" +
                    "${"_"}${buildEnv}" +
                    "${"_"}${buildType}" +
                    "${"_"}${abi}" +
                    "${"_"}${"v"}${version}" +
                    "${"_"}${"b"}${versionCode}" +
                    "${"_"}${formattedDate}.apk"
            if (variant.buildType.name == "release") {
                variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath
                        + "/releaseOutputs")
            }
        }
    }

两个方法解决
1、注释掉自定义输出目录,使用默认目录

//        if (variant.buildType.name == "release") {
//            variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath
//                    + "/releaseOutputs")
//        }

2、在下方加上,跳过这个task

    tasks.whenTaskAdded { task ->
        if (task.name.contains("ReleaseApkListingFileRedirect")) { // 过滤release
            task.enabled = false
        }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容