Android项目,没有引入flutter module时,debug包和release包都正常打包。
引入flutter module后,打debug包正常(打debug包执行的是./gradlew assemblePlayDebug
),但是打release包却报异常(打release包执行的是./gradlew assemblePlayRelease
):
Could not determine the dependencies of task ':app:lintVitalPlayRelease'.
> Could not resolve all artifacts for configuration ':app:playFlipperCompileClasspath'.
> Could not resolve project :flutter.
Required by:
project :app
> Unable to find a matching variant of project :flutter:
- Variant 'debugApiElements' capability com.example.polkawallet:flutter:1.0:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'flipper' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required none 'play' but no value provided.
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Variant 'debugRuntimeElements' capability com.example.polkawallet:flutter:1.0:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'flipper' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required none 'play' but no value provided.
- Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
lintVitalPlayRelease
这个task执行时报错,Play是配置的渠道打包相关的,因此也就可以说是lintVitalRelease
这个task执行时报错,这个task是lint静态代码检查相关的。
原因:
app/build.gradle里面有这段配置脚本:
android {
...
lintOptions {
abortOnError true
baseline file("lint-baseline.xml")
disable "LintError"
}
...
}
lintOptions是静态检查相关的,abortOnError true
即表示lint在执行静态代码检查时如果发现有错误,就会中断构建过程。
解决:
修改lintOptions闭包:
lintOptions {
checkReleaseBuilds false
abortOnError false
baseline file("lint-baseline.xml")
disable "LintError"
}
checkReleaseBuilds在debug时默认是关闭的,但在release时默认是启用的,所以在构建debug包时正常执行,在构建release包时报异常。
可以看下gradle的LintOptions.java中对checkReleaseBuilds的注释:
//com.android.build.gradle.initernal.dsl.LintOptions.java
/**
* Returns whether lint should check for fatal errors during release builds. Default is true.
* If issues with severity "fatal" are found, the release build is aborted.
*/
@Override
@Input
public boolean isCheckReleaseBuilds() {
return checkReleaseBuilds;
}
public void setCheckReleaseBuilds(boolean checkReleaseBuilds) {
this.checkReleaseBuilds = checkReleaseBuilds;
}
参考:
Android Studio打包时候报错:app:lintVitalRelease
Gradle配置lintOptions
Android 打包生成APK文件时报lintOptions配置错误