安卓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
        }
    }

你可能感兴趣的:(安卓AS自定义打包路径报错)