weex build android 时无法设置 outputFile 的问题

问题

运行 weex build android 命令时 ,出现如下错误

BUILD FAILED in 11s

    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at C:\Users\feng\.xtoolkit\node_modules\weexpack\lib\build\android.js:156:20
    at new Promise ()
    at buildApp (C:\Users\feng\.xtoolkit\node_modules\weexpack\lib\build\android.js:152:10)
    at 
Error: Error: Command failed: call gradlew.bat  assembleRelease
isLibProject: false, isAppProject: true
weex_plugin: []

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\feng\Desktop\app\app\platforms\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred configuring project ':app'.
> groovy.lang.GroovyRuntimeException: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[], versionCode=1, versionName=1.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s

weex build android 时无法设置 outputFile 的问题_第1张图片

原因

Android plugin 升级到3.0之后, platforms\android\app\build.gradle 文件中 outputFile 变成了只读属性。

解决办法

  1. all() 代替 each()
  2. outputFileName 代替 output.outputFile

修改之前 platforms\android\app\build.gradle 的内容如下:
weex build android 时无法设置 outputFile 的问题_第2张图片

修改之后 platforms\android\app\build.gradle 的内容如下:

  applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${variant.name}-${variant.versionName}.apk"
        }
    }

weex build android 时无法设置 outputFile 的问题_第3张图片

参考:
1.Android Gradle 3.0.0-alpha2 plugin, Cannot set the value of read-only property ‘outputFile’
2.迁移到 Android Plugin for Gradle 3.0.0

你可能感兴趣的:(weex)