不能勾选签名

今天打包时发现签名的V1和V2都不能选择了,原来是studio的版本升级到了3.1.3,然而Gradle的并版本却是2.2版本,而签名必须要studio的版本大于2.3版本并且Gradle的版本大于2.2版本才能同时勾选的,因此修改Gradle的版本即可勾选V1和V2签名了。

V1和V2 签名

V1:可对签名后的文件,作适当修改,并重新压缩。
V2:不能对签名后的 APK作任何修改,包括 zipalign。因为它是针对字节进行的签名,所以任何改动都会影响最终结果。
Signature Versions不能只选择 V2(Full APK Signature),应该选择V1(Jar Signature),或者选择 V1和 V2,否则无法安装使用。

flavors错误

修改Gradle版本后可以签名了,但是打包就会报错:

Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com

译:所有的flavors都必须属于同一个维度。

本来以为是版本号的原因,但是我检查发现module的版本号和主app都是一致的。

官方:Plugin 3.0.0之后有一种自动匹配消耗库的机制,便于debug variant 自动消耗一个库,然后就是必须要所有的flavor 都属于同一个维度。为了避免flavor 不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。

说实话,还是不太懂,不明白这个所谓的纬度是由什么来决定的,直接贴上解决办法吧:

在主app的build.gradle里面的defaultConfig中添加

flavorDimensions "versionCode"

butter knife报错

flavors错误解决后发现 butter knife打包也会报错。

Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)

Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.

See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

译:


现在必须显式声明注释处理器。发现编译类路径上的以下依赖项包含注释处理器。请将它们添加到annotationProcessor配置中。——butterknife-7.0.1。jar(com.jakewharton:butterknife 7.0.1):
或者,设置android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true以继续前面的行为。请注意,此选项已被废弃,将来将被删除。
有关详细信息,请参阅https://developer.android.com/r/tools/annotationprocess-error -message.html。

解决办法:在app的build中的defaultConfig里面添加

javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }