使用 gradle 插件 2.2.0 未生成 "unaligned" apk,破坏了 Spoon runner
No "unaligned" apks are generated with gradle plugin 2.2.0, breaking Spoon runner
使用 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 and comment here: 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 需要这些 "unaligned" apks 才能 运行 它是测试 运行ner:
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 只接收 "unaligned".
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)
您是否尝试过在 gradle 文件中将 zipalign 设置为 false?
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
zipAlignEnabled false
}
}
如果需要,您还可以指定多个 buildTypes
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
zipAlignEnabled false
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
在 2.2 之前,gradle 插件会生成一个未对齐的 apk,然后 运行 zipalign 来对齐它。因此,生成了两个 apk,一个带有“-unaligned”,另一个没有任何特定标记对齐。
在 2.2 中,与此相关的构建管道有很多改进:
- APK 现在是增量构建的,这意味着当更改单个文件时,APK 中只会更新该文件。
- 生成的 APK 是对齐的,不需要额外的对齐步骤。
这两个中的最后一个在 APK 中启用 V2 签名 (https://source.android.com/security/apksigning/v2.html):完整的 APK 签名可以抵抗 APK 中的任何更改(并且验证速度更快)。这意味着 zipalign 不能再在启用了这些签名的 APK 上 运行。
因此,简而言之,从 2.2 打包开始速度更快、增量并且不会生成不必要的未对齐 APK。
使用 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 and comment here: 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 需要这些 "unaligned" apks 才能 运行 它是测试 运行ner:
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 只接收 "unaligned".
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)
您是否尝试过在 gradle 文件中将 zipalign 设置为 false?
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
zipAlignEnabled false
}
}
如果需要,您还可以指定多个 buildTypes
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
zipAlignEnabled false
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
在 2.2 之前,gradle 插件会生成一个未对齐的 apk,然后 运行 zipalign 来对齐它。因此,生成了两个 apk,一个带有“-unaligned”,另一个没有任何特定标记对齐。
在 2.2 中,与此相关的构建管道有很多改进:
- APK 现在是增量构建的,这意味着当更改单个文件时,APK 中只会更新该文件。
- 生成的 APK 是对齐的,不需要额外的对齐步骤。
这两个中的最后一个在 APK 中启用 V2 签名 (https://source.android.com/security/apksigning/v2.html):完整的 APK 签名可以抵抗 APK 中的任何更改(并且验证速度更快)。这意味着 zipalign 不能再在启用了这些签名的 APK 上 运行。
因此,简而言之,从 2.2 打包开始速度更快、增量并且不会生成不必要的未对齐 APK。