1515# limitations under the License.
1616
1717# Integration tests for R8 desugaring with and without --desugar_java8_libs.
18- #
19- # These tests verify that:
20- # 1. When --desugar_java8_libs is enabled, R8 rewrites java.* calls to j$.*
21- # backports AND the j$.* implementation classes are included in the APK.
22- # 2. When --nodesugar_java8_libs is set, no j$.* classes appear in the APK
23- # and java.* calls remain as-is.
24- # 3. DurationUser is retained in both cases (proguard keep rule).
2518
2619# --- begin runfiles.bash initialization v2 ---
2720# Copy-pasted from the Bazel Bash runfiles library v2.
@@ -34,50 +27,36 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
3427 { echo>&2 " ERROR: cannot find $f " ; exit 1; }; f=; set -e
3528# --- end runfiles.bash initialization v2 ---
3629
37- source " $( rlocation rules_android/test/bashunit/unittest.bash) " || \
38- (echo >&2 " Failed to locate bashunit.sh" && exit 1)
39-
40- source " $( rlocation rules_android/test/rules/android_binary/r8_integration/r8_desugaring_helper.sh) " || \
41- (echo >&2 " Failed to locate r8_desugaring_helper.sh" && exit 1)
30+ source " $( rlocation rules_android/test/rules/android_binary/r8_integration/r8_integration_helper.sh) " || \
31+ (echo >&2 " Failed to locate r8_integration_helper.sh" && exit 1)
4232
4333# Test: with --desugar_java8_libs enabled, R8 desugars java.time APIs and the
4434# backport implementation classes (j$.*) are included in the APK.
4535function test_desugaring_enabled() {
46- build_desugaring_app --desugar_java8_libs
36+ build_app --desugar_java8_libs
4737
48- # DurationUser must be retained by proguard keep rules.
49- apk_dex_contains ' Lcom/desugaring/test/DurationUser;' || \
38+ apk_dex_contains ' Lcom/test/app/DurationUser;' || \
5039 fail " DurationUser class not found in DEX"
5140
52- # Duration.toSeconds() (API 31) must be desugared: the raw java.time
53- # invocation is rewritten to a j$.time backport, so the original
54- # method reference should not appear in the constant pool.
5541 if apk_dex_contains ' java/time/Duration;.*toSeconds' ; then
5642 fail " Expected Duration.toSeconds() to be desugared but raw java/time reference found"
5743 fi
5844
59- # The j$.* backport implementation classes must be present. Without them
60- # the app crashes at runtime with NoClassDefFoundError (e.g. j$/net/URLEncoder).
6145 apk_dex_contains ' Lj\$/' || \
6246 fail " Expected j\$ .* desugared library classes in the APK"
6347}
6448
6549# Test: with --nodesugar_java8_libs, R8 does not rewrite java.* references
6650# and no desugared library DEX is appended.
6751function test_desugaring_disabled() {
68- build_desugaring_app --nodesugar_java8_libs
52+ build_app --nodesugar_java8_libs
6953
70- # DurationUser must still be retained regardless of the desugaring flag.
71- apk_dex_contains ' Lcom/desugaring/test/DurationUser;' || \
54+ apk_dex_contains ' Lcom/test/app/DurationUser;' || \
7255 fail " DurationUser class not found in DEX"
7356
74- # Without desugaring, java.time.Duration.toSeconds() remains as a direct
75- # call in the DEX. (It will crash on API < 31 devices, but the reference
76- # should be present.)
7757 apk_dex_contains ' java/time/Duration' || \
7858 fail " Expected raw java/time/Duration reference when desugaring is disabled"
7959
80- # No j$.* classes should be present.
8160 if apk_dex_contains ' Lj\$/' ; then
8261 fail " Unexpected j\$ .* desugared library classes when desugaring is disabled"
8362 fi
0 commit comments