Skip to content

Commit

Permalink
Mostly fix release packaging issues for new screenshot apis.
Browse files Browse the repository at this point in the history
- Generate kotlin_module files in locations matching maven
  artifact name, and ensure they are retained in produced .aar/classes.jar to ensure extension functions are recognized
- Don't rename ListenableFuture in espresso core - since androidx.test.core uses the actual ListenableFuture dependency
- Bump version to prep for next release

There is still an issue with the ViewInteraction.captureToImage extension, which gradle does not recognize for an unknown reason.

Partially fixes #1139

PiperOrigin-RevId: 400439447
  • Loading branch information
brettchabot authored and copybara-androidxtest committed Oct 2, 2021
1 parent b2f681d commit df88cdd
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 32 deletions.
20 changes: 10 additions & 10 deletions build_extensions/axt_versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ Ensure UsageTrackerRegistry is updated accordingly when incrementing version num
"""

# AXT versions
RUNNER_VERSION = "1.4.1-alpha02" # stable 1.4.0
RULES_VERSION = "1.4.1-alpha02" # stable 1.4.0
MONITOR_VERSION = "1.5.0-alpha02" # stable 1.4.0
ESPRESSO_VERSION = "3.5.0-alpha02" # stable 3.4.0
CORE_VERSION = "1.4.1-alpha02" # stable 1.4.0
ANDROIDX_JUNIT_VERSION = "1.1.4-alpha02" # stable 1.1.3
ANDROIDX_TRUTH_VERSION = "1.5.0-alpha02" # stable 1.4.0
RUNNER_VERSION = "1.4.1-alpha03" # stable 1.4.0
RULES_VERSION = "1.4.1-alpha03" # stable 1.4.0
MONITOR_VERSION = "1.5.0-alpha03" # stable 1.4.0
ESPRESSO_VERSION = "3.5.0-alpha03" # stable 3.4.0
CORE_VERSION = "1.4.1-alpha03" # stable 1.4.0
ANDROIDX_JUNIT_VERSION = "1.1.4-alpha03" # stable 1.1.3
ANDROIDX_TRUTH_VERSION = "1.5.0-alpha03" # stable 1.4.0
UIAUTOMATOR_VERSION = "2.2.0"
JANK_VERSION = "1.0.1"
SERVICES_VERSION = "1.4.1-alpha02" # stable 1.4.0
ORCHESTRATOR_VERSION = "1.4.1-alpha02" # stable 1.4.0
ANNOTATION_VERSION = "1.0.0-alpha01"
SERVICES_VERSION = "1.4.1-alpha03" # stable 1.4.0
ORCHESTRATOR_VERSION = "1.4.1-alpha03" # stable 1.4.0
ANNOTATION_VERSION = "1.0.0-alpha02"

# Maven dependency versions
ANDROIDX_ANNOTATION_VERSION = "1.2.0"
Expand Down
37 changes: 22 additions & 15 deletions build_extensions/release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def axt_release_lib(
proguard_specs = None,
proguard_library = None,
multidex = "off",
jarjar_rules = "//build_extensions:noJarJarRules.txt",
jarjar_rules = ["//build_extensions:noJarJarRules.txt"],
keep_spec = None,
remove_spec = None,
overlapping_jars = [],
Expand Down Expand Up @@ -81,30 +81,37 @@ def axt_release_lib(
if proguard_specs:
expected_output = ":%s_all_proguard.jar" % name

# Step 3. Rename classes via jarjar
# Step 3. Rename classes via series of jarjar transforms

native.java_binary(
name = "jarjar_bin",
main_class = "org.pantsbuild.jarjar.Main",
runtime_deps = ["@maven//:org_pantsbuild_jarjar"],
visibility = visibility,
)
native.genrule(
name = "%s_jarjared" % name,
srcs = [expected_output],
outs = ["%s_jarjared.jar" % name],
cmd = ("$(location :jarjar_bin) process " +
"$(location %s) '$<' '$@'") % jarjar_rules,
tools = [
jarjar_rules,
":jarjar_bin",
],
visibility = visibility,
)
i = 0
for jarjar_rule in jarjar_rules:
input = expected_output
jarjar_rule_name = "%s_jarjared_%d" % (name, i)
expected_output = "%s.jar" % jarjar_rule_name
native.genrule(
name = jarjar_rule_name,
srcs = [input],
outs = [expected_output],
cmd = ("$(location :jarjar_bin) process " +
"$(location %s) '$<' '$@'") % jarjar_rule,
tools = [
jarjar_rule,
":jarjar_bin",
],
visibility = visibility,
)
i = i + 1

# Step 4. Strip out external dependencies. This produces the final name_no_deps.jar.
remove_from_jar(
name = "%s_no_deps" % name,
jar = ":%s_jarjared.jar" % name,
jar = expected_output,
keep_spec = keep_spec,
remove_spec = remove_spec,
overlapping_jars = overlapping_jars,
Expand Down
7 changes: 6 additions & 1 deletion core/java/androidx/test/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ kt_android_library(
],
),
exports_manifest = 1,
# not supported in bazel
#kotlincopts = [
# "-module-name",
# "androidx.test.core",
#],
manifest = "AndroidManifest.xml",
resource_files = glob(["res/**"]),
tags = ["alt_dep=//core"],
Expand Down Expand Up @@ -78,7 +83,7 @@ axt_release_lib(
name = "core_release",
# keep all androidx.test.core classes except androidx.test.core.R, since that will be
# auto-generated by consuming build system
keep_spec = "androidx/test/core/.*",
keep_spec = "androidx/test/core/.*|META-INF/androidx.test.core.kotlin_module",
remove_spec = "androidx/test/core/R[$$\\.]",
resource_files = glob(["res/**"]),
deps = [
Expand Down
13 changes: 11 additions & 2 deletions espresso/core/java/androidx/test/espresso/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,17 @@ android_library(
axt_release_lib(
name = "espresso_core_release",
custom_package = "androidx.test.espresso.core",
jarjar_rules = "release_jarjar_rules.txt",
keep_spec = "androidx/test/espresso",
# perform a two stage jarjar process
# the first stage renames all references to guava,dagger to espresso.internal namespace so
# external users aren't exposed to dependency version conflicts with those libraries
# the second stage renames guava's ListenableFuture back to its original namespace,
# since com.google.guava:listenablefuture is a proper transitive dependency
jarjar_rules = [
"release_jarjar_rules.txt",
"release_jarjar_rules_stage2.txt",
],
# ensure to include kotlin_module since those define extension functions
keep_spec = "androidx/test/espresso|META-INF/androidx.test.espresso.*.kotlin_module",
overlapping_jars = [
"//espresso/idling_resource/java/androidx/test/espresso:espresso_idling_resource_release_no_deps.jar",
],
Expand Down
7 changes: 7 additions & 0 deletions espresso/core/java/androidx/test/espresso/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,13 @@ package androidx.test.espresso.remote {

}

package androidx.test.espresso.screenshot {

public final class ViewInteractionCapture {
}

}

package androidx.test.espresso.util {

public final class ActivityLifecycles {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule androidx.test.espresso.core.internal.deps.guava.util.concurrent.ListenableFuture com.google.common.util.concurrent.ListenableFuture
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ combine_jars(

axt_release_lib(
name = "espresso_remote_release",
jarjar_rules = "release_jarjar_rules.txt",
jarjar_rules = ["release_jarjar_rules.txt"],
keep_spec = "androidx/test/espresso",
overlapping_jars = [
"//espresso/core/java/androidx/test/espresso:espresso_core_release_no_deps.jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ package(default_visibility = ["//visibility:public"])
kt_android_library(
name = "screenshot",
srcs = glob(["*.kt"]),
# generate the kotlin_module file that defines extensions in the right place
# kotlinopts not supported in bazel
#kotlincopts = [
# "-module-name",
# "androidx.test.espresso.screenshot",
#],
deps = [
"//:androidx_annotation",
"//annotation",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package androidx.test.espresso.screenshot;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.google.common.truth.Truth.assertThat;

import android.graphics.Bitmap;
import androidx.test.core.graphics.BitmapStorage;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.ui.app.MainActivity;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

/** A simple scuba test to ensure captureToImage works from hjava */
@RunWith(AndroidJUnit4.class)
public class ViewInteractionCaptureJavaTest {

@Rule
public ActivityScenarioRule<MainActivity> activityScenarioRule =
new ActivityScenarioRule<>(MainActivity.class);

@Test
public void viewInteractionCapture() throws IOException {
Bitmap bitmap = ViewInteractionCapture.captureToBitmap(onView(withId(R.id.layout)));

assertThat(bitmap).isNotNull();

BitmapStorage.writeToTestStorage(bitmap, "viewInteractionCapture");
}
}
2 changes: 1 addition & 1 deletion espresso/web/java/androidx/test/espresso/web/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android_library(

axt_release_lib(
name = "espresso_web_release",
jarjar_rules = "release_jarjar_rules.txt",
jarjar_rules = ["release_jarjar_rules.txt"],
keep_spec = "androidx.test.espresso.web",
proguard_specs = [
"//:proguard_binary.cfg",
Expand Down
5 changes: 5 additions & 0 deletions ktx/core/java/androidx/test/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ kt_android_library(
srcs = glob(
["**/*.kt"],
),
# not supported in bazel
#kotlincopts = [
# "-module-name",
# "androidx.test.core.ktx",
#],
deps = [
"//:androidx_lifecycle_common",
"//core",
Expand Down
2 changes: 1 addition & 1 deletion runner/android_junit_runner/java/androidx/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android_library(
axt_release_lib(
name = "runner_release",
custom_package = "androidx.test.runner",
jarjar_rules = "release_jarjar_rules.txt",
jarjar_rules = ["release_jarjar_rules.txt"],
keep_spec = "androidx/test",
overlapping_jars = [
"//annotation/java/androidx/test/annotation:annotation_release_no_deps.jar",
Expand Down
2 changes: 1 addition & 1 deletion runner/monitor/java/androidx/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ android_library(
axt_release_lib(
name = "monitor_release",
custom_package = "androidx.test.monitor",
jarjar_rules = "release_jarjar_rules.txt",
jarjar_rules = ["release_jarjar_rules.txt"],
keep_spec = "androidx/test",
overlapping_jars = [
"//annotation/java/androidx/test/annotation:annotation_release_no_deps.jar",
Expand Down

0 comments on commit df88cdd

Please sign in to comment.