Add keep annotations in androidx namespace
The only difference between the source in the androidx.annotation.keep
namespace and the original (now legacy) ones is the namespace and the
header comments, e.g. for AnnotationPattern.java:
diff src/keepanno/java/com/android/tools/r8/keepanno/annotations/AnnotationPattern.java src/keepanno/java/androidx/annotation/keep/AnnotationPattern.java
1,3c1,15
< // Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
< // for details. All rights reserved. Use of this source code is governed by a
< // BSD-style license that can be found in the LICENSE file.
Change-Id: I3369dcb057fb8ec39b43cab2e3e610cc90a26ff2
---
> /*
> * Copyright 2025 The Android Open Source Project
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> * You may obtain a copy of the License at
> *
> * http://www.apache.org/licenses/LICENSE-2.0
> *
> * Unless required by applicable law or agreed to in writing, software
> * distributed under the License is distributed on an "AS IS" BASIS,
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> * See the License for the specific language governing permissions and
> * limitations under the License.
> */
9c21,25
< package com.android.tools.r8.keepanno.annotations;
---
> // ***********************************************************************************
> // MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
> // ***********************************************************************************
>
> package androidx.annotation.keep;
This will build and archive three keep annotations JAR's:
build/libs/keepanno-annotations-androidx.jar
build/libs/keepanno-annotations.jar
build/libs/keepanno-annotations-legacy.jar
Currently keepanno-annotations.jar and keepanno-annotations-legacy.jar
are the same and contains the annotations in the current namespace
(com.android.tools.r8.keepanno.annotations).
Bug: b/392865072
Change-Id: Ifca1ad134913b1d99c96325180013a91d78b062e
diff --git a/d8_r8/keepanno/build.gradle.kts b/d8_r8/keepanno/build.gradle.kts
index f7c128b..02d2e85 100644
--- a/d8_r8/keepanno/build.gradle.kts
+++ b/d8_r8/keepanno/build.gradle.kts
@@ -63,6 +63,22 @@
archiveFileName.set("keepanno-annotations.jar")
}
+ val keepAnnoLegacyAnnotationsJar by registering(Jar::class) {
+ dependsOn(gradle.includedBuild("shared").task(":downloadDeps"))
+ from(sourceSets.main.get().output)
+ include("com/android/tools/r8/keepanno/annotations/*")
+ destinationDirectory.set(getRoot().resolveAll("build", "libs"))
+ archiveFileName.set("keepanno-annotations-legacy.jar")
+ }
+
+ val keepAnnoAndroidXAnnotationsJar by registering(Jar::class) {
+ dependsOn(gradle.includedBuild("shared").task(":downloadDeps"))
+ from(sourceSets.main.get().output)
+ include("androidx/annotation/keep/*")
+ destinationDirectory.set(getRoot().resolveAll("build", "libs"))
+ archiveFileName.set("keepanno-annotations-androidx.jar")
+ }
+
val keepAnnoJar by registering(Jar::class) {
dependsOn(gradle.includedBuild("shared").task(":downloadDeps"))
from(sourceSets.main.get().output)
diff --git a/d8_r8/test_modules/testbase/build.gradle.kts b/d8_r8/test_modules/testbase/build.gradle.kts
index cf20c77..8a3c11b 100644
--- a/d8_r8/test_modules/testbase/build.gradle.kts
+++ b/d8_r8/test_modules/testbase/build.gradle.kts
@@ -115,6 +115,7 @@
from(resourceShrinkerDepsJarTask.outputs.getFiles().map(::zipTree))
from(keepAnnoJarTask.outputs.getFiles().map(::zipTree))
exclude("com/android/tools/r8/keepanno/annotations/**")
+ exclude("androidx/annotation/keep/**")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("deps.jar")
}
diff --git a/src/keepanno/java/androidx/annotation/keep/AnnotationPattern.java b/src/keepanno/java/androidx/annotation/keep/AnnotationPattern.java
new file mode 100644
index 0000000..aac8b68
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/AnnotationPattern.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A pattern structure for matching annotations.
+ *
+ * <p>If no properties are set, the default pattern matches any annotation with a runtime retention
+ * policy.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface AnnotationPattern {
+
+ /**
+ * Define the annotation-name pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining annotation-name:
+ *
+ * <ul>
+ * <li>constant
+ * <li>namePattern
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any annotation name.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String name() default "";
+
+ /**
+ * Define the annotation-name pattern by reference to a {@code Class} constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining annotation-name:
+ *
+ * <ul>
+ * <li>name
+ * <li>namePattern
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any annotation name.
+ *
+ * @return The Class constant that defines the annotation.
+ */
+ Class<?> constant() default Object.class;
+
+ /**
+ * Define the annotation-name pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining annotation-name:
+ *
+ * <ul>
+ * <li>name
+ * <li>constant
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any annotation name.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern namePattern() default @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Specify which retention policies must be set for the annotations.
+ *
+ * <p>Matches annotations with matching retention policies
+ *
+ * @return Retention policies. By default {@code RetentionPolicy.RUNTIME}.
+ */
+ RetentionPolicy[] retention() default {RetentionPolicy.RUNTIME};
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/CheckOptimizedOut.java b/src/keepanno/java/androidx/annotation/keep/CheckOptimizedOut.java
new file mode 100644
index 0000000..122ed7e
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/CheckOptimizedOut.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Mark that an item must be optimized out of the residual program.
+ *
+ * <p>An item is optimized out if its declaration is no longer present in the residual program. This
+ * can happen due to many distinct optimizations. For example, it may be dead code and removed by
+ * the usual shrinking. The item's declaration may also be removed if it could be inlined at all
+ * usages, in which case the output may still contain a value if it was a field, or instructions if
+ * it was a method.
+ *
+ * <p>CAUTION: Because of the dependency on shrinker internal optimizations and details such as
+ * inlining vs merging, the use of this annotation is somewhat unreliable and should be used with
+ * caution. In most cases it is more appropriate to use {@link CheckRemoved}.
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface CheckOptimizedOut {
+
+ String description() default "";
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/CheckRemoved.java b/src/keepanno/java/androidx/annotation/keep/CheckRemoved.java
new file mode 100644
index 0000000..20d2d5d
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/CheckRemoved.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Mark that an item must be fully removed from the residual program.
+ *
+ * <p>Being removed from the program means that the item declaration is not present at all in the
+ * residual program. For example, inlined functions are not considered removed. If content of the
+ * item is allowed to be in the residual, use {@link CheckOptimizedOut}.
+ *
+ * <p>A class is removed if all of its members are removed and no references to the class remain.
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface CheckRemoved {
+
+ String description() default "";
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/ClassAccessFlags.java b/src/keepanno/java/androidx/annotation/keep/ClassAccessFlags.java
new file mode 100644
index 0000000..0d4e765
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/ClassAccessFlags.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+/**
+ * Valid matches on class access flags and their negations.
+ *
+ * <p>The negated elements make it easier to express the inverse as we cannot use a "not/negation"
+ * operation syntactically.
+ */
+public enum ClassAccessFlags {
+ PUBLIC,
+ NON_PUBLIC,
+ PACKAGE_PRIVATE,
+ NON_PACKAGE_PRIVATE,
+ FINAL,
+ NON_FINAL,
+ INTERFACE,
+ NON_INTERFACE,
+ ABSTRACT,
+ NON_ABSTRACT,
+ SYNTHETIC,
+ NON_SYNTHETIC,
+ ANNOTATION,
+ NON_ANNOTATION,
+ ENUM,
+ NON_ENUM
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/ClassNamePattern.java b/src/keepanno/java/androidx/annotation/keep/ClassNamePattern.java
new file mode 100644
index 0000000..299bf04
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/ClassNamePattern.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A pattern structure for matching names of classes and interfaces.
+ *
+ * <p>If no properties are set, the default pattern matches any name of a class or interface.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface ClassNamePattern {
+
+ /**
+ * Define the class-name pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>constant
+ * <li>unqualifiedName
+ * <li>unqualifiedNamePattern
+ * <li>packageName
+ * </ul>
+ *
+ * @return The qualified class name that defines the class.
+ */
+ String name() default "";
+
+ /**
+ * Define the class-name pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>name
+ * <li>unqualifiedName
+ * <li>unqualifiedNamePattern
+ * <li>packageName
+ * </ul>
+ *
+ * @return The class-constant that defines the class.
+ */
+ Class<?> constant() default Object.class;
+
+ /**
+ * Exact and unqualified name of the class or interface.
+ *
+ * <p>For example, the unqualified name of {@code com.example.MyClass} is {@code MyClass}. Note
+ * that for inner classes a `$` will appear in the unqualified name,such as, {@code
+ * MyClass$MyInnerClass}.
+ *
+ * <p>The default matches any unqualified name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-unqualified-name:
+ *
+ * <ul>
+ * <li>unqualifiedNamePattern
+ * <li>name
+ * <li>constant
+ * </ul>
+ */
+ String unqualifiedName() default "";
+
+ /**
+ * Define the unqualified class-name pattern by a string pattern.
+ *
+ * <p>The default matches any unqualified name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-unqualified-name:
+ *
+ * <ul>
+ * <li>unqualifiedName
+ * <li>name
+ * <li>constant
+ * </ul>
+ *
+ * @return The string pattern of the unqualified class name.
+ */
+ StringPattern unqualifiedNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Exact package name of the class or interface.
+ *
+ * <p>For example, the package of {@code com.example.MyClass} is {@code com.example}.
+ *
+ * <p>The default matches any package.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-package-name:
+ *
+ * <ul>
+ * <li>name
+ * <li>constant
+ * </ul>
+ */
+ String packageName() default "";
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/FieldAccessFlags.java b/src/keepanno/java/androidx/annotation/keep/FieldAccessFlags.java
new file mode 100644
index 0000000..9b28dec
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/FieldAccessFlags.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+/**
+ * Valid matches on field access flags and their negations.
+ *
+ * <p>The negated elements make it easier to express the inverse as we cannot use a "not/negation"
+ * operation syntactically.
+ */
+public enum FieldAccessFlags {
+ // General member flags.
+ PUBLIC,
+ NON_PUBLIC,
+ PRIVATE,
+ NON_PRIVATE,
+ PROTECTED,
+ NON_PROTECTED,
+ PACKAGE_PRIVATE,
+ NON_PACKAGE_PRIVATE,
+ STATIC,
+ NON_STATIC,
+ FINAL,
+ NON_FINAL,
+ SYNTHETIC,
+ NON_SYNTHETIC,
+ // Field specific flags.
+ VOLATILE,
+ NON_VOLATILE,
+ TRANSIENT,
+ NON_TRANSIENT,
+ // ENUM - No PG parser support.
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/InstanceOfPattern.java b/src/keepanno/java/androidx/annotation/keep/InstanceOfPattern.java
new file mode 100644
index 0000000..9e55d6a
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/InstanceOfPattern.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A pattern structure for matching instances of classes and interfaces.
+ *
+ * <p>If no properties are set, the default pattern matches any instance.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface InstanceOfPattern {
+
+ /**
+ * True if the pattern should include the directly matched classes.
+ *
+ * <p>If false, the pattern is exclusive and only matches classes that are strict subclasses of
+ * the pattern.
+ */
+ boolean inclusive() default true;
+
+ /** Instances of classes matching the class-name pattern. */
+ ClassNamePattern classNamePattern() default @ClassNamePattern(unqualifiedName = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepBinding.java b/src/keepanno/java/androidx/annotation/keep/KeepBinding.java
new file mode 100644
index 0000000..a15e97e
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepBinding.java
@@ -0,0 +1,722 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A binding of a keep item.
+ *
+ * <p>Bindings allow referencing the exact instance of a match from a condition in other conditions
+ * and/or targets. It can also be used to reduce duplication of targets by sharing patterns.
+ *
+ * <p>An item can be:
+ *
+ * <ul>
+ * <li>a pattern on classes;
+ * <li>a pattern on methods; or
+ * <li>a pattern on fields.
+ * </ul>
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface KeepBinding {
+
+ /**
+ * Name with which other bindings, conditions or targets can reference the bound item pattern.
+ *
+ * @return Name of the binding.
+ */
+ String bindingName();
+
+ /**
+ * Specify the kind of this item pattern.
+ *
+ * <p>Possible values are:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS}
+ * <li>{@link KeepItemKind#ONLY_MEMBERS}
+ * <li>{@link KeepItemKind#ONLY_METHODS}
+ * <li>{@link KeepItemKind#ONLY_FIELDS}
+ * <li>{@link KeepItemKind#CLASS_AND_MEMBERS}
+ * <li>{@link KeepItemKind#CLASS_AND_METHODS}
+ * <li>{@link KeepItemKind#CLASS_AND_FIELDS}
+ * </ul>
+ *
+ * <p>If unspecified the default kind for an item depends on its member patterns:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS} if no member patterns are defined
+ * <li>{@link KeepItemKind#ONLY_METHODS} if method patterns are defined
+ * <li>{@link KeepItemKind#ONLY_FIELDS} if field patterns are defined
+ * <li>{@link KeepItemKind#ONLY_MEMBERS} otherwise.
+ * </ul>
+ *
+ * @return The kind for this pattern.
+ */
+ KeepItemKind kind() default KeepItemKind.DEFAULT;
+
+ /**
+ * Define the class pattern by reference to a binding.
+ *
+ * <p>Mutually exclusive with the following other properties defining class:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class.
+ *
+ * @return The name of the binding that defines the class.
+ */
+ String classFromBinding() default "";
+
+ /**
+ * Define the class-name pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The qualified class name that defines the class.
+ */
+ String className() default "";
+
+ /**
+ * Define the class-name pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-constant that defines the class.
+ */
+ Class<?> classConstant() default Object.class;
+
+ /**
+ * Define the class-name pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-name pattern that defines the class.
+ */
+ ClassNamePattern classNamePattern() default @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassName() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassNameExclusive() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstant() default Object.class;
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstantExclusive() default Object.class;
+
+ /**
+ * Define the instance-of with a pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The pattern that defines what instance-of the class must be.
+ */
+ InstanceOfPattern instanceOfPattern() default @InstanceOfPattern();
+
+ /**
+ * Define the class-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String classAnnotatedByClassName() default "";
+
+ /**
+ * Define the class-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> classAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the class-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern classAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodNamePattern` also defining method-name.
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodName` also defining method-name.
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameters` also defining parameters.
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldNamePattern` also defining field-name.
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldName` also defining field-name.
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepCondition.java b/src/keepanno/java/androidx/annotation/keep/KeepCondition.java
new file mode 100644
index 0000000..1a0cd79
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepCondition.java
@@ -0,0 +1,745 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A condition for a keep edge.
+ *
+ * <p>The condition denotes an item used as a precondition of a rule. An item can be:
+ *
+ * <ul>
+ * <li>a pattern on classes;
+ * <li>a pattern on methods; or
+ * <li>a pattern on fields.
+ * </ul>
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface KeepCondition {
+
+ /**
+ * Define the class pattern by reference to a binding.
+ *
+ * <p>Mutually exclusive with the following other properties defining class:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class.
+ *
+ * @return The name of the binding that defines the class.
+ */
+ String classFromBinding() default "";
+
+ /**
+ * Define the class-name pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The qualified class name that defines the class.
+ */
+ String className() default "";
+
+ /**
+ * Define the class-name pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-constant that defines the class.
+ */
+ Class<?> classConstant() default Object.class;
+
+ /**
+ * Define the class-name pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-name pattern that defines the class.
+ */
+ ClassNamePattern classNamePattern() default @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassName() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassNameExclusive() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstant() default Object.class;
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstantExclusive() default Object.class;
+
+ /**
+ * Define the instance-of with a pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The pattern that defines what instance-of the class must be.
+ */
+ InstanceOfPattern instanceOfPattern() default @InstanceOfPattern();
+
+ /**
+ * Define the class-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String classAnnotatedByClassName() default "";
+
+ /**
+ * Define the class-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> classAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the class-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern classAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member pattern in full by a reference to a binding.
+ *
+ * <p>Mutually exclusive with all other class and member pattern properties. When a member binding
+ * is referenced this item is defined to be that item, including its class and member patterns.
+ *
+ * @return The binding name that defines the member.
+ */
+ String memberFromBinding() default "";
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining member-access.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining method-access.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-name:
+ *
+ * <ul>
+ * <li>methodNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-name:
+ *
+ * <ul>
+ * <li>methodName
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the following other properties defining parameters:
+ *
+ * <ul>
+ * <li>methodParameterTypePatterns
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the following other properties defining parameters:
+ *
+ * <ul>
+ * <li>methodParameters
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining field-access.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-name:
+ *
+ * <ul>
+ * <li>fieldNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-name:
+ *
+ * <ul>
+ * <li>fieldName
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepConstraint.java b/src/keepanno/java/androidx/annotation/keep/KeepConstraint.java
new file mode 100644
index 0000000..19f48dc
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepConstraint.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+
+package androidx.annotation.keep;
+
+/**
+ * Usage constraints for how a target is used and what must be kept.
+ *
+ * <p>Providing the constraints on how an item is being used allows shrinkers to optimize or remove
+ * aspects of the item that do not change that usage constraint.
+ *
+ * <p>For example, invoking a method reflectively does not use any annotations on that method, and
+ * it is safe to remove the annotations. However, it would not be safe to remove parameters from the
+ * method.
+ */
+public enum KeepConstraint {
+ /**
+ * Indicates that the target item is being looked up reflectively.
+ *
+ * <p>Looking up an item reflectively requires that it remains on its expected context, which for
+ * a method or field means it must remain on its defining class. In other words, the item cannot
+ * be removed or moved.
+ *
+ * <p>Note that looking up a member does not imply that the holder class of the member can be
+ * looked up. If both the class and the member need to be looked, make sure to have a target for
+ * both.
+ *
+ * <p>Note also that the item can be looked up within its context but no constraint is placed on
+ * its name, accessibility or any other properties of the item.
+ *
+ * <p>If assumptions are being made about other aspects, additional constraints and targets should
+ * be added to the keep annotation.
+ */
+ LOOKUP,
+
+ /**
+ * Indicates that the name of the target item is being used.
+ *
+ * <p>This usage constraint is needed if the target is being looked up reflectively by using its
+ * name. Setting it will prohibit renaming of the target item.
+ *
+ * <p>Note that preserving the name of a member does not imply that the holder class of the member
+ * will preserve its qualified or simple name. If both the class and the member need to preserve
+ * their names, make sure to have a target for both.
+ *
+ * <p>Note that preserving the name of a member does not preserve the types of its parameters or
+ * its return type for methods or the type for fields.
+ */
+ NAME,
+
+ /**
+ * Indicates that the visibility of the target must be at least as visible as declared.
+ *
+ * <p>Setting this constraint ensures that any (reflective) access to the target that is allowed
+ * remains valid. In other words, a public class, field or method must remain public. For a
+ * non-public target its visibility may be relaxed in the direction: {@code private ->
+ * package-private -> protected -> public}.
+ *
+ * <p>Note that this constraint does not place any restrictions on any other accesses flags than
+ * visibility. In particular, flags such a static, final and abstract may change.
+ *
+ * <p>Used together with {@link #VISIBILITY_RESTRICT} the visibility will remain invariant.
+ */
+ VISIBILITY_RELAX,
+
+ /**
+ * Indicates that the visibility of the target must be at most as visible as declared.
+ *
+ * <p>Setting this constraint ensures that any (reflective) access to the target that would fail
+ * will continue to fail. In other words, a private class, field or method must remain private.
+ * Concretely the visibility of the target item may be restricted in the direction: {@code public
+ * -> protected -> package-private -> private}.
+ *
+ * <p>Note that this constraint does not place any restrictions on any other accesses flags than
+ * visibility. In particular, flags such a static, final and abstract may change.
+ *
+ * <p>Used together with {@link #VISIBILITY_RELAX} the visibility will remain invariant.
+ */
+ VISIBILITY_RESTRICT,
+
+ /**
+ * Indicates that the visibility of the target must remain as declared.
+ *
+ * <p>Note that this constraint does not place any restrictions on any other accesses flags than
+ * visibility. In particular, flags such a static, final and abstract may change.
+ *
+ * <p>This is equivalent to using both {@link #VISIBILITY_RELAX} and {@link #VISIBILITY_RESTRICT}.
+ */
+ VISIBILITY_INVARIANT,
+
+ /**
+ * Indicates that the class target is being instantiated reflectively.
+ *
+ * <p>This usage constraint is only valid on class targets.
+ *
+ * <p>Being instantiated prohibits reasoning about the class instances at compile time. In other
+ * words, the compiler must assume the class to be possibly instantiated at all times.
+ *
+ * <p>Note that the constraint {@link KeepConstraint#LOOKUP} is needed to reflectively obtain a
+ * class. This constraint only implies that if the class is referenced in the program it may be
+ * instantiated.
+ */
+ CLASS_INSTANTIATE,
+
+ /**
+ * Indicates that the method target is being invoked reflectively.
+ *
+ * <p>This usage constraint is only valid on method targets.
+ *
+ * <p>To be invoked reflectively the method must retain the structure of the method. Thus, unused
+ * arguments cannot be removed. However, it does not imply preserving the types of its parameters
+ * or its return type. If the parameter types are being obtained reflectively then those need a
+ * keep target independent of the method.
+ *
+ * <p>Note that the constraint {@link KeepConstraint#LOOKUP} is needed to reflectively obtain a
+ * method reference. This constraint only implies that if the method is referenced in the program
+ * it may be reflectively invoked.
+ */
+ METHOD_INVOKE,
+
+ /**
+ * Indicates that the field target is reflectively read from.
+ *
+ * <p>This usage constraint is only valid on field targets.
+ *
+ * <p>A field that has its value read from, requires that the field value must remain. Thus, if
+ * field remains, its value cannot be replaced. It can still be removed in full, be inlined and
+ * its value reasoned about at compile time.
+ *
+ * <p>Note that the constraint {@link KeepConstraint#LOOKUP} is needed to reflectively obtain
+ * access to the field. This constraint only implies that if a field is referenced then it may be
+ * reflectively read.
+ */
+ FIELD_GET,
+
+ /**
+ * Indicates that the field target is reflectively written to.
+ *
+ * <p>This usage constraint is only valid on field targets.
+ *
+ * <p>A field that has its value written to, requires that the field value must be treated as
+ * unknown.
+ *
+ * <p>Note that the constraint {@link KeepConstraint#LOOKUP} is needed to reflectively obtain
+ * access to the field. This constraint only implies that if a field is referenced then it may be
+ * reflectively written.
+ */
+ FIELD_SET,
+
+ /**
+ * Indicates that the target method can be replaced by an alternative definition at runtime.
+ *
+ * <p>This usage constraint is only valid on method targets.
+ *
+ * <p>Replacing a method implies that the concrete implementation of the target cannot be known at
+ * compile time. Thus, it cannot be moved or otherwise assumed to have particular properties.
+ * Being able to replace the method still allows the compiler to fully remove it if it is
+ * statically found to be unused.
+ *
+ * <p>Note also that no restriction is placed on the method name. To ensure the same name add
+ * {@link #NAME} to the constraint set.
+ */
+ METHOD_REPLACE,
+
+ /**
+ * Indicates that the target field can be replaced by an alternative definition at runtime.
+ *
+ * <p>This usage constraint is only valid on field targets.
+ *
+ * <p>Replacing a field implies that the concrete implementation of the target cannot be known at
+ * compile time. Thus, it cannot be moved or otherwise assumed to have particular properties.
+ * Being able to replace the method still allows the compiler to fully remove it if it is
+ * statically found to be unused.
+ *
+ * <p>Note also that no restriction is placed on the field name. To ensure the same name add
+ * {@link #NAME} to the constraint set.
+ */
+ FIELD_REPLACE,
+
+ /**
+ * Indicates that the target item must never be inlined or merged.
+ *
+ * <p>This ensures that if the item is actually used in the program it will remain in some form.
+ * For example, a method may still be renamed, but it will be present as a frame in stack traces
+ * produced by the runtime (before potentially being retraced). For classes, they too may be
+ * renamed, but will not have been merged with other classes or have their allocations fully
+ * eliminated (aka class inlining).
+ *
+ * <p>For members this also ensures that the field value or method body cannot be reasoned about
+ * outside the item itself. For example, a field value cannot be assumed to be a particular value,
+ * and a method cannot be assumed to have particular properties for callers, such as always
+ * throwing or a constant return value.
+ */
+ NEVER_INLINE,
+
+ /**
+ * Indicates that the class hierarchy below the target class may be extended at runtime.
+ *
+ * <p>This ensures that new subtypes of the target class can later be linked and/or class loaded
+ * at runtime.
+ *
+ * <p>This does not ensure that the class remains if it is otherwise dead code and can be fully
+ * removed.
+ *
+ * <p>Note that this constraint does not ensure that particular methods remain on the target
+ * class. If methods or fields of the target class are being targeted by a subclass that was
+ * classloaded or linked later, then keep annotations are needed for those targets too. Such
+ * non-visible uses requires the same annotations to preserve as for reflective uses.
+ */
+ CLASS_OPEN_HIERARCHY,
+
+ /**
+ * Indicates that the target item must retain its generic signature if present.
+ *
+ * <p>This ensures that the generic signature remains, but does not prohibit rewriting of the
+ * generic signature. For example, if a type present in the generic signature is renamed, the
+ * generic signature will also be updated to now refer to the type by its renamed name.
+ *
+ * <p>Note that this constraint does not otherwise restrict what can be done to the target, such
+ * as removing the target completely, inlining it, etc.
+ */
+ GENERIC_SIGNATURE,
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepEdge.java b/src/keepanno/java/androidx/annotation/keep/KeepEdge.java
new file mode 100644
index 0000000..b4e3830
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepEdge.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface KeepEdge {
+ String description() default "";
+
+ KeepBinding[] bindings() default {};
+
+ KeepCondition[] preconditions() default {};
+
+ KeepTarget[] consequences();
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepForApi.java b/src/keepanno/java/androidx/annotation/keep/KeepForApi.java
new file mode 100644
index 0000000..7ad9e61
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepForApi.java
@@ -0,0 +1,481 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to mark a class, field or method as part of a library API surface.
+ *
+ * <p>When a class is annotated, member patterns can be used to define which members are to be kept.
+ * When no member patterns are specified the default pattern matches all public and protected
+ * members.
+ *
+ * <p>When a member is annotated, the member patterns cannot be used as the annotated member itself
+ * fully defines the item to be kept (i.e., itself).
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface KeepForApi {
+
+ /**
+ * Optional description to document the reason for this annotation.
+ *
+ * @return The descriptive message. Defaults to no description.
+ */
+ String description() default "";
+
+ /**
+ * Additional targets to be kept as part of the API surface.
+ *
+ * @return List of additional target consequences. Defaults to no additional target consequences.
+ */
+ KeepTarget[] additionalTargets() default {};
+
+ /**
+ * Specify the kind of this item pattern.
+ *
+ * <p>Default kind is {@link KeepItemKind#CLASS_AND_MEMBERS}, meaning the annotated class and/or
+ * member is to be kept. When annotating a class this can be set to {@link
+ * KeepItemKind#ONLY_CLASS} to avoid patterns on any members. That can be useful when the API
+ * members are themselves explicitly annotated.
+ *
+ * <p>It is not possible to use {@link KeepItemKind#ONLY_CLASS} if annotating a member. Also, it
+ * is never valid to use kind {@link KeepItemKind#ONLY_MEMBERS} as the API surface must keep the
+ * class if any member is to be accessible.
+ *
+ * @return The kind for this pattern.
+ */
+ KeepItemKind kind() default KeepItemKind.DEFAULT;
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodNamePattern` also defining method-name.
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodName` also defining method-name.
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameters` also defining parameters.
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldNamePattern` also defining field-name.
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldName` also defining field-name.
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepItemKind.java b/src/keepanno/java/androidx/annotation/keep/KeepItemKind.java
new file mode 100644
index 0000000..5ffc9d7
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepItemKind.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+public enum KeepItemKind {
+ ONLY_CLASS,
+ ONLY_MEMBERS,
+ ONLY_METHODS,
+ ONLY_FIELDS,
+ CLASS_AND_MEMBERS,
+ CLASS_AND_METHODS,
+ CLASS_AND_FIELDS,
+ DEFAULT
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepOption.java b/src/keepanno/java/androidx/annotation/keep/KeepOption.java
new file mode 100644
index 0000000..b635d1c
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepOption.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+public enum KeepOption {
+ SHRINKING,
+ OPTIMIZATION,
+ OBFUSCATION,
+ ACCESS_MODIFICATION,
+ ANNOTATION_REMOVAL,
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/KeepTarget.java b/src/keepanno/java/androidx/annotation/keep/KeepTarget.java
new file mode 100644
index 0000000..96196a9
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/KeepTarget.java
@@ -0,0 +1,842 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A target for a keep edge.
+ *
+ * <p>The target denotes an item along with options for what to keep. An item can be:
+ *
+ * <ul>
+ * <li>a pattern on classes;
+ * <li>a pattern on methods; or
+ * <li>a pattern on fields.
+ * </ul>
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface KeepTarget {
+
+ /**
+ * Specify the kind of this item pattern.
+ *
+ * <p>Possible values are:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS}
+ * <li>{@link KeepItemKind#ONLY_MEMBERS}
+ * <li>{@link KeepItemKind#ONLY_METHODS}
+ * <li>{@link KeepItemKind#ONLY_FIELDS}
+ * <li>{@link KeepItemKind#CLASS_AND_MEMBERS}
+ * <li>{@link KeepItemKind#CLASS_AND_METHODS}
+ * <li>{@link KeepItemKind#CLASS_AND_FIELDS}
+ * </ul>
+ *
+ * <p>If unspecified the default kind for an item depends on its member patterns:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS} if no member patterns are defined
+ * <li>{@link KeepItemKind#ONLY_METHODS} if method patterns are defined
+ * <li>{@link KeepItemKind#ONLY_FIELDS} if field patterns are defined
+ * <li>{@link KeepItemKind#ONLY_MEMBERS} otherwise.
+ * </ul>
+ *
+ * @return The kind for this pattern.
+ */
+ KeepItemKind kind() default KeepItemKind.DEFAULT;
+
+ /**
+ * Define the usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target.
+ *
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
+ * </ul>
+ *
+ * <p>For classes the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
+ * </ul>
+ *
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
+ * </ul>
+ *
+ * <p>Mutually exclusive with the property `constraintAdditions` also defining constraints.
+ *
+ * @return Usage constraints for the target.
+ */
+ KeepConstraint[] constraints() default {};
+
+ /**
+ * Add additional usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target in addition to the default
+ * constraints.
+ *
+ * <p>The default constraints are documented in {@link #constraints}
+ *
+ * <p>Mutually exclusive with the property `constraints` also defining constraints.
+ *
+ * @return Additional usage constraints for the target.
+ */
+ KeepConstraint[] constraintAdditions() default {};
+
+ /**
+ * Patterns for annotations that must remain on the item.
+ *
+ * <p>The annotations matching any of the patterns must remain on the item if the annotation types
+ * remain in the program.
+ *
+ * <p>Note that if the annotation types themselves are unused/removed, then their references on
+ * the item will be removed too. If the annotation types themselves are used reflectively then
+ * they too need a keep annotation or rule to ensure they remain in the program.
+ *
+ * <p>By default no annotation patterns are defined and no annotations are required to remain.
+ *
+ * @return Annotation patterns
+ */
+ AnnotationPattern[] constrainAnnotations() default {};
+
+ /**
+ * Define the class pattern by reference to a binding.
+ *
+ * <p>Mutually exclusive with the following other properties defining class:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class.
+ *
+ * @return The name of the binding that defines the class.
+ */
+ String classFromBinding() default "";
+
+ /**
+ * Define the class-name pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>classConstant
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The qualified class name that defines the class.
+ */
+ String className() default "";
+
+ /**
+ * Define the class-name pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-constant that defines the class.
+ */
+ Class<?> classConstant() default Object.class;
+
+ /**
+ * Define the class-name pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-name:
+ *
+ * <ul>
+ * <li>className
+ * <li>classConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class name.
+ *
+ * @return The class-name pattern that defines the class.
+ */
+ ClassNamePattern classNamePattern() default @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassName() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances of the fully qualified class name.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The qualified class name that defines what instance-of the class must be.
+ */
+ String instanceOfClassNameExclusive() default "";
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstantExclusive
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstant() default Object.class;
+
+ /**
+ * Define the instance-of pattern as classes that are instances the referenced Class constant.
+ *
+ * <p>The pattern is exclusive in that it does not match classes that are instances of the
+ * pattern, but only those that are instances of classes that are subclasses of the pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfPattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The class constant that defines what instance-of the class must be.
+ */
+ Class<?> instanceOfClassConstantExclusive() default Object.class;
+
+ /**
+ * Define the instance-of with a pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining instance-of:
+ *
+ * <ul>
+ * <li>instanceOfClassName
+ * <li>instanceOfClassNameExclusive
+ * <li>instanceOfClassConstant
+ * <li>instanceOfClassConstantExclusive
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class instance.
+ *
+ * @return The pattern that defines what instance-of the class must be.
+ */
+ InstanceOfPattern instanceOfPattern() default @InstanceOfPattern();
+
+ /**
+ * Define the class-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassConstant
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String classAnnotatedByClassName() default "";
+
+ /**
+ * Define the class-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassNamePattern
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> classAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the class-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining class-annotated-by:
+ *
+ * <ul>
+ * <li>classAnnotatedByClassName
+ * <li>classAnnotatedByClassConstant
+ * <li>classFromBinding
+ * </ul>
+ *
+ * <p>If none are specified the default is to match any class regardless of what the class is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern classAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member pattern in full by a reference to a binding.
+ *
+ * <p>Mutually exclusive with all other class and member pattern properties. When a member binding
+ * is referenced this item is defined to be that item, including its class and member patterns.
+ *
+ * @return The binding name that defines the member.
+ */
+ String memberFromBinding() default "";
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining member-access.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining method-access.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-name:
+ *
+ * <ul>
+ * <li>methodNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-name:
+ *
+ * <ul>
+ * <li>methodName
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the following other properties defining parameters:
+ *
+ * <ul>
+ * <li>methodParameterTypePatterns
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the following other properties defining parameters:
+ *
+ * <ul>
+ * <li>methodParameters
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * <p>Mutually exclusive with the property `memberFromBinding` also defining field-access.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-name:
+ *
+ * <ul>
+ * <li>fieldNamePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-name:
+ *
+ * <ul>
+ * <li>fieldName
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * <li>memberFromBinding
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/MemberAccessFlags.java b/src/keepanno/java/androidx/annotation/keep/MemberAccessFlags.java
new file mode 100644
index 0000000..dd6c1d6
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/MemberAccessFlags.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+/**
+ * Valid matches on member access flags and their negations.
+ *
+ * <p>The negated elements make it easier to express the inverse as we cannot use a "not/negation"
+ * operation syntactically.
+ */
+public enum MemberAccessFlags {
+ PUBLIC,
+ NON_PUBLIC,
+ PROTECTED,
+ NON_PROTECTED,
+ PACKAGE_PRIVATE,
+ NON_PACKAGE_PRIVATE,
+ PRIVATE,
+ NON_PRIVATE,
+ STATIC,
+ NON_STATIC,
+ FINAL,
+ NON_FINAL,
+ SYNTHETIC,
+ NON_SYNTHETIC
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/MethodAccessFlags.java b/src/keepanno/java/androidx/annotation/keep/MethodAccessFlags.java
new file mode 100644
index 0000000..9b9fca0
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/MethodAccessFlags.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+/**
+ * Valid matches on method access flags and their negations.
+ *
+ * <p>The negated elements make it easier to express the inverse as we cannot use a "not/negation"
+ * operation syntactically.
+ */
+public enum MethodAccessFlags {
+ // General member flags.
+ PUBLIC,
+ NON_PUBLIC,
+ PRIVATE,
+ NON_PRIVATE,
+ PROTECTED,
+ NON_PROTECTED,
+ PACKAGE_PRIVATE,
+ NON_PACKAGE_PRIVATE,
+ STATIC,
+ NON_STATIC,
+ FINAL,
+ NON_FINAL,
+ SYNTHETIC,
+ NON_SYNTHETIC,
+ // Method specific flags.
+ SYNCHRONIZED,
+ NON_SYNCHRONIZED,
+ BRIDGE,
+ NON_BRIDGE,
+ // VARARGS - No PG parser support
+ NATIVE,
+ NON_NATIVE,
+ ABSTRACT,
+ NON_ABSTRACT,
+ STRICT_FP,
+ NON_STRICT_FP
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/StringPattern.java b/src/keepanno/java/androidx/annotation/keep/StringPattern.java
new file mode 100644
index 0000000..0a0d803
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/StringPattern.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A pattern structure for matching strings.
+ *
+ * <p>If no properties are set, the default pattern matches any string.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface StringPattern {
+
+ /**
+ * Exact string content.
+ *
+ * <p>For example, {@code "foo"} or {@code "java.lang.String"}.
+ *
+ * <p>Mutually exclusive with the following other properties defining string-exact-pattern:
+ *
+ * <ul>
+ * <li>startsWith
+ * <li>endsWith
+ * </ul>
+ */
+ String exact() default "";
+
+ /**
+ * Matches strings beginning with the given prefix.
+ *
+ * <p>For example, {@code "get"} to match strings such as {@code "getMyValue"}.
+ *
+ * <p>Mutually exclusive with the property `exact` also defining string-prefix-pattern.
+ */
+ String startsWith() default "";
+
+ /**
+ * Matches strings ending with the given suffix.
+ *
+ * <p>For example, {@code "Setter"} to match strings such as {@code "myValueSetter"}.
+ *
+ * <p>Mutually exclusive with the property `exact` also defining string-suffix-pattern.
+ */
+ String endsWith() default "";
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/TypePattern.java b/src/keepanno/java/androidx/annotation/keep/TypePattern.java
new file mode 100644
index 0000000..71b41aa
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/TypePattern.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A pattern structure for matching types.
+ *
+ * <p>If no properties are set, the default pattern matches any type.
+ *
+ * <p>All properties on this annotation are mutually exclusive.
+ */
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface TypePattern {
+
+ /**
+ * Exact type name as a string.
+ *
+ * <p>For example, {@code "long"} or {@code "java.lang.String"}.
+ *
+ * <p>Mutually exclusive with the following other properties defining type-pattern:
+ *
+ * <ul>
+ * <li>constant
+ * <li>classNamePattern
+ * <li>instanceOfPattern
+ * </ul>
+ */
+ String name() default "";
+
+ /**
+ * Exact type from a class constant.
+ *
+ * <p>For example, {@code String.class}.
+ *
+ * <p>Mutually exclusive with the following other properties defining type-pattern:
+ *
+ * <ul>
+ * <li>name
+ * <li>classNamePattern
+ * <li>instanceOfPattern
+ * </ul>
+ */
+ Class<?> constant() default Object.class;
+
+ /**
+ * Classes matching the class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining type-pattern:
+ *
+ * <ul>
+ * <li>name
+ * <li>constant
+ * <li>instanceOfPattern
+ * </ul>
+ */
+ ClassNamePattern classNamePattern() default @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the instance-of with a pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining type-pattern:
+ *
+ * <ul>
+ * <li>name
+ * <li>constant
+ * <li>classNamePattern
+ * </ul>
+ *
+ * @return The pattern that defines what instance-of the class must be.
+ */
+ InstanceOfPattern instanceOfPattern() default @InstanceOfPattern();
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/UsedByNative.java b/src/keepanno/java/androidx/annotation/keep/UsedByNative.java
new file mode 100644
index 0000000..955bc95
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/UsedByNative.java
@@ -0,0 +1,571 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to mark a class, field or method as being accessed from native code via JNI.
+ *
+ * <p>Note: Before using this annotation, consider if instead you can annotate the code that is
+ * doing reflection with {@link UsesReflection}. Annotating the reflecting code is generally more
+ * clear and maintainable, and it also naturally gives rise to edges that describe just the
+ * reflected aspects of the program. The {@link UsedByReflection} annotation is suitable for cases
+ * where the reflecting code is not under user control, or in migrating away from rules.
+ *
+ * <p>When a class is annotated, member patterns can be used to define which members are to be kept.
+ * When no member patterns are specified the default pattern is to match just the class.
+ *
+ * <p>When a member is annotated, the member patterns cannot be used as the annotated member itself
+ * fully defines the item to be kept (i.e., itself).
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface UsedByNative {
+
+ /**
+ * Optional description to document the reason for this annotation.
+ *
+ * @return The descriptive message. Defaults to no description.
+ */
+ String description() default "";
+
+ /**
+ * Conditions that should be satisfied for the annotation to be in effect.
+ *
+ * @return The list of preconditions. Defaults to no conditions, thus trivially/unconditionally
+ * satisfied.
+ */
+ KeepCondition[] preconditions() default {};
+
+ /**
+ * Additional targets to be kept in addition to the annotated class/members.
+ *
+ * @return List of additional target consequences. Defaults to no additional target consequences.
+ */
+ KeepTarget[] additionalTargets() default {};
+
+ /**
+ * Specify the kind of this item pattern.
+ *
+ * <p>If unspecified the default kind depends on the annotated item.
+ *
+ * <p>When annotating a class the default kind is:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS} if no member patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_METHODS} if method patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_FIELDS} if field patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_MEMBERS} otherwise.
+ * </ul>
+ *
+ * <p>When annotating a method the default kind is: {@link KeepItemKind#ONLY_METHODS}
+ *
+ * <p>When annotating a field the default kind is: {@link KeepItemKind#ONLY_FIELDS}
+ *
+ * <p>It is not possible to use {@link KeepItemKind#ONLY_CLASS} if annotating a member.
+ *
+ * @return The kind for this pattern.
+ */
+ KeepItemKind kind() default KeepItemKind.DEFAULT;
+
+ /**
+ * Define the usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target.
+ *
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
+ * </ul>
+ *
+ * <p>For classes the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
+ * </ul>
+ *
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
+ * </ul>
+ *
+ * <p>Mutually exclusive with the property `constraintAdditions` also defining constraints.
+ *
+ * @return Usage constraints for the target.
+ */
+ KeepConstraint[] constraints() default {};
+
+ /**
+ * Add additional usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target in addition to the default
+ * constraints.
+ *
+ * <p>The default constraints are documented in {@link #constraints}
+ *
+ * <p>Mutually exclusive with the property `constraints` also defining constraints.
+ *
+ * @return Additional usage constraints for the target.
+ */
+ KeepConstraint[] constraintAdditions() default {};
+
+ /**
+ * Patterns for annotations that must remain on the item.
+ *
+ * <p>The annotations matching any of the patterns must remain on the item if the annotation types
+ * remain in the program.
+ *
+ * <p>Note that if the annotation types themselves are unused/removed, then their references on
+ * the item will be removed too. If the annotation types themselves are used reflectively then
+ * they too need a keep annotation or rule to ensure they remain in the program.
+ *
+ * <p>By default no annotation patterns are defined and no annotations are required to remain.
+ *
+ * @return Annotation patterns
+ */
+ AnnotationPattern[] constrainAnnotations() default {};
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodNamePattern` also defining method-name.
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodName` also defining method-name.
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameters` also defining parameters.
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldNamePattern` also defining field-name.
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldName` also defining field-name.
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/UsedByReflection.java b/src/keepanno/java/androidx/annotation/keep/UsedByReflection.java
new file mode 100644
index 0000000..7cf8b09
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/UsedByReflection.java
@@ -0,0 +1,571 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to mark a class, field or method as being accessed reflectively.
+ *
+ * <p>Note: Before using this annotation, consider if instead you can annotate the code that is
+ * doing reflection with {@link UsesReflection}. Annotating the reflecting code is generally more
+ * clear and maintainable, and it also naturally gives rise to edges that describe just the
+ * reflected aspects of the program. The {@link UsedByReflection} annotation is suitable for cases
+ * where the reflecting code is not under user control, or in migrating away from rules.
+ *
+ * <p>When a class is annotated, member patterns can be used to define which members are to be kept.
+ * When no member patterns are specified the default pattern is to match just the class.
+ *
+ * <p>When a member is annotated, the member patterns cannot be used as the annotated member itself
+ * fully defines the item to be kept (i.e., itself).
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface UsedByReflection {
+
+ /**
+ * Optional description to document the reason for this annotation.
+ *
+ * @return The descriptive message. Defaults to no description.
+ */
+ String description() default "";
+
+ /**
+ * Conditions that should be satisfied for the annotation to be in effect.
+ *
+ * @return The list of preconditions. Defaults to no conditions, thus trivially/unconditionally
+ * satisfied.
+ */
+ KeepCondition[] preconditions() default {};
+
+ /**
+ * Additional targets to be kept in addition to the annotated class/members.
+ *
+ * @return List of additional target consequences. Defaults to no additional target consequences.
+ */
+ KeepTarget[] additionalTargets() default {};
+
+ /**
+ * Specify the kind of this item pattern.
+ *
+ * <p>If unspecified the default kind depends on the annotated item.
+ *
+ * <p>When annotating a class the default kind is:
+ *
+ * <ul>
+ * <li>{@link KeepItemKind#ONLY_CLASS} if no member patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_METHODS} if method patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_FIELDS} if field patterns are defined;
+ * <li>{@link KeepItemKind#CLASS_AND_MEMBERS} otherwise.
+ * </ul>
+ *
+ * <p>When annotating a method the default kind is: {@link KeepItemKind#ONLY_METHODS}
+ *
+ * <p>When annotating a field the default kind is: {@link KeepItemKind#ONLY_FIELDS}
+ *
+ * <p>It is not possible to use {@link KeepItemKind#ONLY_CLASS} if annotating a member.
+ *
+ * @return The kind for this pattern.
+ */
+ KeepItemKind kind() default KeepItemKind.DEFAULT;
+
+ /**
+ * Define the usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target.
+ *
+ * <p>The default constraints depend on the kind of the target. For all targets the default
+ * constraints include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#LOOKUP}
+ * <li>{@link KeepConstraint#NAME}
+ * <li>{@link KeepConstraint#VISIBILITY_RELAX}
+ * </ul>
+ *
+ * <p>For classes the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#CLASS_INSTANTIATE}
+ * </ul>
+ *
+ * <p>For methods the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#METHOD_INVOKE}
+ * </ul>
+ *
+ * <p>For fields the default constraints also include:
+ *
+ * <ul>
+ * <li>{@link KeepConstraint#FIELD_GET}
+ * <li>{@link KeepConstraint#FIELD_SET}
+ * </ul>
+ *
+ * <p>Mutually exclusive with the property `constraintAdditions` also defining constraints.
+ *
+ * @return Usage constraints for the target.
+ */
+ KeepConstraint[] constraints() default {};
+
+ /**
+ * Add additional usage constraints of the target.
+ *
+ * <p>The specified constraints must remain valid for the target in addition to the default
+ * constraints.
+ *
+ * <p>The default constraints are documented in {@link #constraints}
+ *
+ * <p>Mutually exclusive with the property `constraints` also defining constraints.
+ *
+ * @return Additional usage constraints for the target.
+ */
+ KeepConstraint[] constraintAdditions() default {};
+
+ /**
+ * Patterns for annotations that must remain on the item.
+ *
+ * <p>The annotations matching any of the patterns must remain on the item if the annotation types
+ * remain in the program.
+ *
+ * <p>Note that if the annotation types themselves are unused/removed, then their references on
+ * the item will be removed too. If the annotation types themselves are used reflectively then
+ * they too need a keep annotation or rule to ensure they remain in the program.
+ *
+ * <p>By default no annotation patterns are defined and no annotations are required to remain.
+ *
+ * @return Annotation patterns
+ */
+ AnnotationPattern[] constrainAnnotations() default {};
+
+ /**
+ * Define the member-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassConstant
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String memberAnnotatedByClassName() default "";
+
+ /**
+ * Define the member-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> memberAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the member-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining member-annotated-by:
+ *
+ * <ul>
+ * <li>memberAnnotatedByClassName
+ * <li>memberAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * <p>If none are specified the default is to match any member regardless of what the member is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern memberAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the member-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field and method properties as use restricts the match to both
+ * types of members.
+ *
+ * @return The member access-flag constraints that must be met.
+ */
+ MemberAccessFlags[] memberAccess() default {};
+
+ /**
+ * Define the method-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassConstant
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String methodAnnotatedByClassName() default "";
+
+ /**
+ * Define the method-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> methodAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the method-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining method-annotated-by:
+ *
+ * <ul>
+ * <li>methodAnnotatedByClassName
+ * <li>methodAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none are specified the default is to match any method regardless of what the method is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern methodAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the method-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * method-access flags.
+ *
+ * @return The method access-flag constraints that must be met.
+ */
+ MethodAccessFlags[] methodAccess() default {};
+
+ /**
+ * Define the method-name pattern by an exact method name.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodNamePattern` also defining method-name.
+ *
+ * @return The exact method name of the method.
+ */
+ String methodName() default "";
+
+ /**
+ * Define the method-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any method
+ * name.
+ *
+ * <p>Mutually exclusive with the property `methodName` also defining method-name.
+ *
+ * @return The string pattern of the method name.
+ */
+ StringPattern methodNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the method return-type pattern by a fully qualified type or 'void'.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnTypeConstant
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return The qualified type name of the method return type.
+ */
+ String methodReturnType() default "";
+
+ /**
+ * Define the method return-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypePattern
+ * </ul>
+ *
+ * @return A class constant denoting the type of the method return type.
+ */
+ Class<?> methodReturnTypeConstant() default Object.class;
+
+ /**
+ * Define the method return-type pattern by a type pattern.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any return
+ * type.
+ *
+ * <p>Mutually exclusive with the following other properties defining return-type:
+ *
+ * <ul>
+ * <li>methodReturnType
+ * <li>methodReturnTypeConstant
+ * </ul>
+ *
+ * @return The pattern of the method return type.
+ */
+ TypePattern methodReturnTypePattern() default @TypePattern(name = "");
+
+ /**
+ * Define the method parameters pattern by a list of fully qualified types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
+ *
+ * @return The list of qualified type names of the method parameters.
+ */
+ String[] methodParameters() default {""};
+
+ /**
+ * Define the method parameters pattern by a list of patterns on types.
+ *
+ * <p>Mutually exclusive with all field properties.
+ *
+ * <p>If none, and other properties define this item as a method, the default matches any
+ * parameters.
+ *
+ * <p>Mutually exclusive with the property `methodParameters` also defining parameters.
+ *
+ * @return The list of type patterns for the method parameters.
+ */
+ TypePattern[] methodParameterTypePatterns() default {@TypePattern(name = "")};
+
+ /**
+ * Define the field-annotated-by pattern by fully qualified class name.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassConstant
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The qualified class name that defines the annotation.
+ */
+ String fieldAnnotatedByClassName() default "";
+
+ /**
+ * Define the field-annotated-by pattern by reference to a Class constant.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassNamePattern
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-constant that defines the annotation.
+ */
+ Class<?> fieldAnnotatedByClassConstant() default Object.class;
+
+ /**
+ * Define the field-annotated-by pattern by reference to a class-name pattern.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-annotated-by:
+ *
+ * <ul>
+ * <li>fieldAnnotatedByClassName
+ * <li>fieldAnnotatedByClassConstant
+ * </ul>
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none are specified the default is to match any field regardless of what the field is
+ * annotated by.
+ *
+ * @return The class-name pattern that defines the annotation.
+ */
+ ClassNamePattern fieldAnnotatedByClassNamePattern() default
+ @ClassNamePattern(unqualifiedName = "");
+
+ /**
+ * Define the field-access pattern by matching on access flags.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any
+ * field-access flags.
+ *
+ * @return The field access-flag constraints that must be met.
+ */
+ FieldAccessFlags[] fieldAccess() default {};
+
+ /**
+ * Define the field-name pattern by an exact field name.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldNamePattern` also defining field-name.
+ *
+ * @return The exact field name of the field.
+ */
+ String fieldName() default "";
+
+ /**
+ * Define the field-name pattern by a string pattern.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any field
+ * name.
+ *
+ * <p>Mutually exclusive with the property `fieldName` also defining field-name.
+ *
+ * @return The string pattern of the field name.
+ */
+ StringPattern fieldNamePattern() default @StringPattern(exact = "");
+
+ /**
+ * Define the field-type pattern by a fully qualified type.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldTypeConstant
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The qualified type name for the field type.
+ */
+ String fieldType() default "";
+
+ /**
+ * Define the field-type pattern by a class constant.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypePattern
+ * </ul>
+ *
+ * @return The class constant for the field type.
+ */
+ Class<?> fieldTypeConstant() default Object.class;
+
+ /**
+ * Define the field-type pattern by a pattern on types.
+ *
+ * <p>Mutually exclusive with all method properties.
+ *
+ * <p>If none, and other properties define this item as a field, the default matches any type.
+ *
+ * <p>Mutually exclusive with the following other properties defining field-type:
+ *
+ * <ul>
+ * <li>fieldType
+ * <li>fieldTypeConstant
+ * </ul>
+ *
+ * @return The type pattern for the field type.
+ */
+ TypePattern fieldTypePattern() default @TypePattern(name = "");
+}
diff --git a/src/keepanno/java/androidx/annotation/keep/UsesReflection.java b/src/keepanno/java/androidx/annotation/keep/UsesReflection.java
new file mode 100644
index 0000000..0d7ca88
--- /dev/null
+++ b/src/keepanno/java/androidx/annotation/keep/UsesReflection.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ***********************************************************************************
+// GENERATED FILE. DO NOT EDIT! See KeepItemAnnotationGenerator.java.
+// ***********************************************************************************
+
+// ***********************************************************************************
+// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.
+// ***********************************************************************************
+
+package androidx.annotation.keep;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to declare the reflective usages made by a class, method or field.
+ *
+ * <p>The annotation's 'value' is a list of targets to be kept if the annotated item is used. The
+ * annotated item is a precondition for keeping any of the specified targets. Thus, if an annotated
+ * method is determined to be unused by the program, the annotation itself will not be in effect and
+ * the targets will not be kept (assuming nothing else is otherwise keeping them).
+ *
+ * <p>The annotation's 'additionalPreconditions' is optional and can specify additional conditions
+ * that should be satisfied for the annotation to be in effect.
+ *
+ * <p>The translation of the {@link UsesReflection} annotation into a {@link KeepEdge} is as
+ * follows:
+ *
+ * <p>Assume the item of the annotation is denoted by 'CTX' and referred to as its context.
+ *
+ * <pre>
+ * @UsesReflection(value = targets, [additionalPreconditions = preconditions])
+ * ==>
+ * @KeepEdge(
+ * consequences = targets,
+ * preconditions = {createConditionFromContext(CTX)} + preconditions
+ * )
+ *
+ * where
+ * KeepCondition createConditionFromContext(ctx) {
+ * if (ctx.isClass()) {
+ * return new KeepCondition(classTypeName = ctx.getClassTypeName());
+ * }
+ * if (ctx.isMethod()) {
+ * return new KeepCondition(
+ * classTypeName = ctx.getClassTypeName(),
+ * methodName = ctx.getMethodName(),
+ * methodReturnType = ctx.getMethodReturnType(),
+ * methodParameterTypes = ctx.getMethodParameterTypes());
+ * }
+ * if (ctx.isField()) {
+ * return new KeepCondition(
+ * classTypeName = ctx.getClassTypeName(),
+ * fieldName = ctx.getFieldName()
+ * fieldType = ctx.getFieldType());
+ * }
+ * // unreachable
+ * }
+ * </pre>
+ */
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+@Retention(RetentionPolicy.CLASS)
+public @interface UsesReflection {
+
+ /**
+ * Optional description to document the reason for this annotation.
+ *
+ * @return The descriptive message. Defaults to no description.
+ */
+ String description() default "";
+
+ /**
+ * Consequences that must be kept if the annotation is in effect.
+ *
+ * @return The list of target consequences.
+ */
+ KeepTarget[] value();
+
+ /**
+ * Additional preconditions for the annotation to be in effect.
+ *
+ * @return The list of additional preconditions. Defaults to no additional preconditions.
+ */
+ KeepCondition[] additionalPreconditions() default {};
+}
diff --git a/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java b/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
index 10ac930..e267bdd 100644
--- a/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
+++ b/src/test/java/com/android/tools/r8/keepanno/utils/KeepItemAnnotationGenerator.java
@@ -83,8 +83,7 @@
"",
"// ***********************************************************************************",
"// MAINTAINED AND TESTED IN THE R8 REPO. PLEASE MAKE CHANGES THERE AND REPLICATE.",
- "// ***********************************************************************************",
- "");
+ "// ***********************************************************************************");
return result;
}
@@ -2253,13 +2252,9 @@
lines.stream()
.map(s -> StringUtils.replaceAll(s, R8_ANNO_PKG, ANDROIDX_ANNO_PKG))
.collect(Collectors.toList()));
- // TODO(b/392865072): Write the annotation files to the androidx namespace.
- if (false) {
- FileUtils.writeTextFile(toResolved, out);
- }
+ FileUtils.writeTextFile(toResolved, out);
}
- // TODO(b/392865072): Write the annotation files to the androidx namespace.
- for (String pkg : new String[] {R8_ANNO_PKG /*, ANDROIDX_ANNO_PKG*/}) {
+ for (String pkg : new String[] {R8_ANNO_PKG, ANDROIDX_ANNO_PKG}) {
writeFile(
pkg, generator -> generator.STRING_PATTERN, Generator::generateStringPattern, write);
writeFile(pkg, generator -> generator.TYPE_PATTERN, Generator::generateTypePattern, write);
diff --git a/tools/archive.py b/tools/archive.py
index 4f73c47..61b49c6 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -202,6 +202,8 @@
utils.GRADLE_TASK_CONSOLIDATED_LICENSE,
utils.GRADLE_TASK_KEEP_ANNO_JAR,
utils.GRADLE_TASK_KEEP_ANNO_DOC,
+ utils.GRADLE_TASK_KEEP_ANNO_LEGACY_JAR,
+ utils.GRADLE_TASK_KEEP_ANNO_ANDROIDX_JAR,
utils.GRADLE_TASK_R8,
utils.GRADLE_TASK_R8LIB, utils.GRADLE_TASK_R8LIB_NO_DEPS,
utils.GRADLE_TASK_THREADING_MODULE_BLOCKING,
@@ -288,6 +290,8 @@
utils.DESUGAR_CONFIGURATION_JDK11_MAVEN_ZIP,
utils.DESUGAR_CONFIGURATION_JDK11_NIO_MAVEN_ZIP, utils.R8_SRC_JAR,
utils.KEEPANNO_ANNOTATIONS_JAR,
+ utils.KEEPANNO_LEGACY_ANNOTATIONS_JAR,
+ utils.KEEPANNO_ANDROIDX_ANNOTATIONS_JAR,
utils.GENERATED_LICENSE,
'd8_r8/main/build/spdx/r8.spdx.json'
]
diff --git a/tools/utils.py b/tools/utils.py
index 1e26ee9..0354cd9 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -45,6 +45,8 @@
GRADLE_TASK_CLEAN_TEST = ':test:cleanTest'
GRADLE_TASK_CONSOLIDATED_LICENSE = ':main:consolidatedLicense'
GRADLE_TASK_KEEP_ANNO_JAR = ':keepanno:keepAnnoAnnotationsJar'
+GRADLE_TASK_KEEP_ANNO_LEGACY_JAR = ':keepanno:keepAnnoLegacyAnnotationsJar'
+GRADLE_TASK_KEEP_ANNO_ANDROIDX_JAR = ':keepanno:keepAnnoAndroidXAnnotationsJar'
GRADLE_TASK_KEEP_ANNO_DOC = ':keepanno:keepAnnoAnnotationsDoc'
GRADLE_TASK_MAIN_COMPILE = ':main:compileJava'
GRADLE_TASK_R8 = ':main:r8WithRelocatedDeps'
@@ -90,6 +92,8 @@
KEEPANNO_ANNOTATIONS_JAR = os.path.join(LIBS, 'keepanno-annotations.jar')
KEEPANNO_ANNOTATIONS_DOC = os.path.join('d8_r8', 'keepanno', 'build', 'docs',
'javadoc')
+KEEPANNO_LEGACY_ANNOTATIONS_JAR = os.path.join(LIBS, 'keepanno-annotations-legacy.jar')
+KEEPANNO_ANDROIDX_ANNOTATIONS_JAR = os.path.join(LIBS, 'keepanno-annotations-androidx.jar')
DESUGAR_CONFIGURATION = os.path.join('src', 'library_desugar',
'desugar_jdk_libs.json')