From 538c7855e7d369a3d5aab9eb9815172847dd4e84 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Mon, 23 Aug 2021 11:11:22 +0300 Subject: [PATCH] Android: guard getStateCount() with correct VERSION.SDK_INT The call getStateCount() was introduced in 29, so cases for lower API should be handled. Change-Id: I7f58541c0b16fed91835e6f390afa89378a7af3e Reviewed-by: Ville Voutilainen (cherry picked from commit 760e24e8676d52e2851ef8556770194a97eae831) Reviewed-by: Qt Cherry-pick Bot --- .../jar/src/org/qtproject/qt/android/ExtractStyle.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java index 5d2d56010a5..f60748dad6a 100644 --- a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java +++ b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java @@ -69,6 +69,7 @@ import android.graphics.drawable.RotateDrawable; import android.graphics.drawable.ScaleDrawable; import android.graphics.drawable.StateListDrawable; import android.graphics.drawable.VectorDrawable; +import android.os.Build; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; @@ -413,7 +414,12 @@ public class ExtractStyle { try { StateListDrawable stateList = (StateListDrawable) drawable; JSONArray array = new JSONArray(); - for (int i = 0; i < stateList.getStateCount(); i++) { + final int numStates; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) + numStates = (Integer) StateListDrawable.class.getMethod("getStateCount").invoke(stateList); + else + numStates = stateList.getStateCount(); + for (int i = 0; i < numStates; i++) { JSONObject stateJson = new JSONObject(); final Drawable d = (Drawable) StateListDrawable.class.getMethod("getStateDrawable", Integer.TYPE).invoke(stateList, i); final int[] states = (int[]) StateListDrawable.class.getMethod("getStateSet", Integer.TYPE).invoke(stateList, i);