android-gradle插件2.2.0不会生成“未对齐”的apk,从而打破了SpoonRunner

使用android gradle插件2.2.0:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:2.2.0"
    }
}

并运行./gradlew assembleDebug assembleDebugAndroidTest:

使用2.2.0:

app-debug.apk
app-debug-androidTest.apk

与2.1.3:

app-debug.apk
app-debug-unaligned.apk
app-debug-androidTest.apk
app-debug-androidTest-unaligned.apk

基于此Google问题:https://code.google.com/p/android/issues/detail?id=212591,并在此处评论:https://code.google.com/p/android/issues/detail?id=212591#c15

Hi, we don’t generate unaligned apks any more. As part of the
improvements to speed things, we generate the apk already aligned. So,
instead of two, you just get the final one.

Spoon需要这些“未对齐”的apk来运行它的测试运行程序:

java -jar spoon-runner-1.7.0-jar-with-dependencies.jar \
    --debug --fail-on-failure --adb-timeout 90 --no-animations \
    --apk app-debug.apk \
    --test-apk app-debug-androidTest-unaligned.apk

错误:

12:06:48 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'java.lang.NoClassDefFoundError''
2016-09-23 12:06:48 [STRL.testRunStarted] testCount=0 runName=<>.test
2016-09-23 12:06:48 [STRL.testRunFailed] errorMessage=Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
2016-09-23 12:06:48 [STRL.testRunEnded] elapsedTime=0
12:06:48 I/XmlResultReporter: XML test result file generated at /<>/spoon-output/junit-reports/emulator-5554.xml. Total tests 0, 

看起来Spoon只接受“未对齐”.

Exception in thread "main" java.lang.IllegalArgumentException: Instrumentation APK path does not exist.
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
    at com.squareup.spoon.SpoonRunner$Builder.setInstrumentationApk(SpoonRunner.java:360)
    at com.squareup.spoon.SpoonRunner.main(SpoonRunner.java:657)

解决方法:

在2.2之前的版本中,gradle插件将生成未对齐的apk,然后运行zipalign对其进行对齐.因此,产生了两个apk,其中一个带有“ -unaligned”,另一个是没有任何特殊标记的对齐.

在2.2版本中,与此相关的构建管道有了很多改进:

>现在会以增量方式构建APK,这意味着当更改单个文件时,APK中只会更新该文件.
>生成的APK是对齐的,不需要额外的对齐步骤.

这两个中的最后一个启用APK(https://source.android.com/security/apksigning/v2.html)中的V2签名:完整的APK签名,可抵抗APK中的任何更改(并且验证速度更快).这意味着zipalign不再可以在启用了这些签名的APK上运行.

因此,简而言之,从2.2打包开始的速度更快,增量且不会生成不必要的未对齐APK.

上一篇:kettle安装及初步使用


下一篇:kettle突然退出,双击Spoon.bat后闪退