From 2319e56366cc53fa19de741129282fc67e3cdecb Mon Sep 17 00:00:00 2001 From: Sebastien Hertz Date: Thu, 31 Mar 2016 16:48:26 +0200 Subject: [PATCH] Fix code coverage for apps When building apps with EMMA_INSTRUMENT=true, we must ensure that jacoco is at least on the classpath (or even embedded for unbundled branches) and that proguard will ignore jacoco classes. Otherwise the Jack compilation would fail. For unbundled build, we include the proguard configuration file build/core/proguard.jacoco.flags to ignore jacoco classes. For full build, we ensure jacoco is on the classpath during the jack compilation. Bug: 27607712 (cherry picked from commit d9641e01f300ffc359a034a3e897fd8ada78237a) Change-Id: Ib46c91d03721f2418b15c17546d4f322f2f90a28 --- core/package_internal.mk | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/package_internal.mk b/core/package_internal.mk index 65b65be36..69666256e 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -191,8 +191,21 @@ LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent else # ! EMMA_INSTRUMENT_STATIC ifdef LOCAL_SDK_VERSION ifdef TARGET_BUILD_APPS +# In unbundled build, merge the coverage library into the apk. # Jack supports coverage with Jacoco LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent +# Exclude jacoco classes from proguard +LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags +LOCAL_JACK_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags +else # ! TARGET_BUILD_APPS +# If build against the SDK in full build, core.jar is not used +# so coverage classes are not present. +# Jack needs jacoco on the classpath but we do not want it to be in +# the final apk. While it is a static library, we add it to the +# LOCAL_JAVA_LIBRARIES which are only present on the classpath. +# Note: we have nothing to do for proguard since jacoco will be +# on the classpath only, thus not modified during the compilation. +LOCAL_JAVA_LIBRARIES += jacocoagent endif # TARGET_BUILD_APPS endif # LOCAL_SDK_VERSION endif # ! EMMA_INSTRUMENT_STATIC