Android gradle plug-in 2.2.0 does not generate “misaligned” apks, breaking spoonrunner

Using Android gradle plug-in 2.2.0:

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

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

And run. / gradlew assemblydebug assemblydebugandoidtest:

Use 2.2.0:

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

And 2.1.3:

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

Based on this question: https://code.google.com/p/android/issues/detail?id=212591 , and comment here: https://code.google.com/p/android/issues/detail?id=212591#c15 :

Spoon needs these "misaligned" apks to run its test runner:

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

Error:

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, 

It seems that spoon only accepts "misaligned"

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)

resolvent:

In versions before 2.2, the gradle plug-in will generate misaligned apks and then run zippalign to align them. Therefore, two apks are generated, one with "- unaligned" and the other without any special marks

In version 2.2, there are many improvements in the build pipeline related to this:

>The APK will now be built incrementally, which means that when a single file is changed, only the file will be updated in the APK. > the generated APK is aligned and no additional alignment steps are required

The last of the two enables APK( https://source.android.com/security/apksigning/v2.html )V2 signature in: the complete APK signature can resist any changes in the APK (and the verification speed is faster). This means that ziphalign can no longer run on apks with these signatures enabled

Therefore, in short, starting with 2.2 packaging is faster, incremental, and does not generate unnecessary misaligned apks

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>