Skip to content

Android 12 non-SDK restrictions reflection is unsupported #233

@rid-x

Description

@rid-x

After analyzing my app with the veridex tool, I found that there are two use cases for the reflection API in the Apptentive Android SDK.

Reflection unsupported Landroid/graphics/Typeface;->sSystemFontMap use(s):
  Lcom/apptentive/android/sdk/util/Util;->replaceDefaultFont(Landroid/content/Context;Ljava/lang/String;)V
  Lcom/apptentive/android/sdk/util/Util;->replaceDefaultFont(Landroid/content/Context;Ljava/lang/String;)V

The reason for this log is reflection field API usage getDeclaredField and it could break the app on Android 12. Here you can see the code snippet from Apptentive Android SDK.

com.apptentive.android.sdk.util.Util#replaceDefaultFont

try {
	final Field staticField = Typeface.class.getDeclaredField("sSystemFontMap");
	staticField.setAccessible(true);
	staticField.set(null, newMap);
} catch (NoSuchFieldException e) {
	ApptentiveLog.e(e, "Exception replacing system font");
	logException(e);
} catch (IllegalAccessException e) {
	ApptentiveLog.e(e, "Exception replacing system font");
	logException(e);
}
.....
try {
	final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName);
	staticField.setAccessible(true);
	staticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
	ApptentiveLog.e(e, "Exception replacing system font");
	logException(e);
} catch (IllegalAccessException e) {
	ApptentiveLog.e(e, "Exception replacing system font");
	logException(e);
}

The functionality of the replaceDefaultFont method, which currently relies on reflection, needs to be replaced with some supported API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions