diff --git a/app/build.gradle b/app/build.gradle index 20cc07683..c212c8bfc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,11 +14,11 @@ apply plugin: 'com.android.application' apply plugin: 'de.mobilej.unmock' android { - compileSdk 32 + compileSdk 33 defaultConfig { applicationId 'io.appium.uiautomator2' minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 147 archivesBaseName = 'appium-uiautomator2' /** diff --git a/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java b/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java index a5fff017a..04b7168a5 100644 --- a/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java +++ b/app/src/main/java/io/appium/uiautomator2/utils/AXWindowHelpers.java @@ -16,6 +16,7 @@ package io.appium.uiautomator2.utils; +import android.accessibilityservice.AccessibilityService; import android.os.Build; import android.os.SystemClock; import android.view.accessibility.AccessibilityNodeInfo; @@ -28,6 +29,9 @@ import java.util.Objects; import static androidx.test.internal.util.Checks.checkNotNull; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import io.appium.uiautomator2.common.exceptions.UiAutomator2Exception; import io.appium.uiautomator2.core.UiAutomatorBridge; import io.appium.uiautomator2.model.internal.CustomUiDevice; @@ -47,8 +51,13 @@ public class AXWindowHelpers { */ private static void clearAccessibilityCache() { try { - // This call invokes `AccessibilityInteractionClient.getInstance().clearCache();` method - UiAutomatorBridge.getInstance().getUiAutomation().setServiceInfo(null); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + AccessibilityService accessibilityService = getInstrumentation().getContext().getSystemService(AccessibilityService.class); + accessibilityService.clearCache(); + } else { + // This call invokes `AccessibilityInteractionClient.getInstance().clearCache();` method + UiAutomatorBridge.getInstance().getUiAutomation().setServiceInfo(null); + } } catch (NullPointerException npe) { // it is fine // ignore