Android studio 3.0 引起的 outputFile sync failed:not vaild

在Android studio 3.0 之前 我们自定义apk名称使用如下方式:

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(output.outputFile.parent, variant.applicationId + "-" + buildType.name+"-" +defaultConfig.versionName + "-" + defaultConfig.versionCode + "-${releaseTime() }.apk" );
        }
    }

但是更新到as3.0以后,会同步失败。stackoverflow上有人(http://stackoverflow.com/questions/44044031/grade-plugin-3-alpha1-outputfile-causes-error)说:

This build error occurs because variant-specific tasks are no longer created during the configuration stage.
This results in the plugin not knowing all of its outputs up front, but it also means faster configuration times.
As an alternative, we will introduce new APIs to provide similar functionality.

查询官网介绍:https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#variant_api

API change in variant output
解决方案:

applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName=" ${variant.applicationId}- ${ buildType.name}- ${defaultConfig.versionName}-${ defaultConfig.versionCode }-${releaseTime() }.apk"
        }
    }

猜你喜欢

转载自blog.csdn.net/Marvinhq/article/details/72794077