Skip to content

Commit 87bbba2

Browse files
Merge pull request #2266 from android:monitorrepro
PiperOrigin-RevId: 662239437
2 parents d4eff99 + 6589fc9 commit 87bbba2

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

runner/monitor/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
**Bug Fixes**
88

99
* Catch and log NoSuchMethodError on forceEnableAppTracing calls
10+
* Fix ActivityInvoker$-CC ClassNotFoundErrors when used with older androidx.test:core
1011

1112
**New Features**
1213

runner/monitor/java/androidx/test/BUILD

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ kt_android_library(
3535
"internal/runner/runtime/ExposedInstrumentationApi.java",
3636
"internal/runner/hidden/ExposedInstrumentationApi.java",
3737
"internal/platform/app/ActivityInvoker$$CC.java",
38+
"internal/platform/app/ActivityInvokerDesugar.java",
3839
],
3940
),
4041
tags = ["alt_dep=//runner/monitor"],
@@ -81,6 +82,7 @@ android_library(
8182
srcs = [
8283
# only needed for external release backwards compatibility
8384
"internal/platform/app/ActivityInvoker$$CC.java",
85+
"internal/platform/app/ActivityInvokerDesugar.java",
8486
],
8587
custom_package = "androidx.test.monitor",
8688
manifest = "AndroidManifest.xml",
@@ -108,6 +110,7 @@ axt_android_aar(
108110
"androidx.test.runner",
109111
],
110112
included_dep = ":monitor_release_lib",
113+
jarjar_rule = ":jarjar.txt",
111114
)
112115

113116
maven_artifact(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package androidx.test.internal.platform.app;
2+
3+
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
4+
5+
import android.app.Activity;
6+
import android.content.ComponentName;
7+
import android.content.Intent;
8+
import androidx.annotation.RestrictTo;
9+
import androidx.annotation.RestrictTo.Scope;
10+
11+
/**
12+
* Handles default implementation for ActivityInvoker#getIntentForActivity
13+
*
14+
* <p>See the {@link ActivityInvoker$$CC} javadoc for prior history.
15+
*
16+
* <p>Starting in androidx.test:monitor:1.6.X, a new version of the desugar tooling was used that
17+
* generated a ActivityInvoker$-CC class. Class names with hyphens are rejected by javac, so we
18+
* cannot directly declare a ActivityInvoker$-CC class here. So instead we use a placeholder name,
19+
* and use jarjar to rename the class after the javac step.
20+
*
21+
* @hide
22+
*/
23+
@RestrictTo(Scope.LIBRARY_GROUP)
24+
public final class ActivityInvokerDesugar {
25+
26+
private ActivityInvokerDesugar() {}
27+
28+
// the method name must exactly match the name generated by desugar
29+
@SuppressWarnings("MethodName")
30+
public static Intent $default$getIntentForActivity(
31+
ActivityInvoker invoker, Class<? extends Activity> activityClass) {
32+
Intent intent =
33+
Intent.makeMainActivity(
34+
new ComponentName(getInstrumentation().getTargetContext(), activityClass));
35+
if (getInstrumentation().getTargetContext().getPackageManager().resolveActivity(intent, 0)
36+
!= null) {
37+
return intent;
38+
}
39+
return Intent.makeMainActivity(
40+
new ComponentName(getInstrumentation().getContext(), activityClass));
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rule androidx.test.internal.platform.app.ActivityInvokerDesugar androidx.test.internal.platform.app.ActivityInvoker$-CC

0 commit comments

Comments
 (0)