dimanche 13 juin 2021

Android R.raw.class.getFields() returns no fields on release

I have following code (located in static method in public class, called on app start from MainActivity.onPostCreate):

Field[] fields = R.raw.class.getFields();
StringBuilder allFields = new StringBuilder();

for (int i = 0; i < fields.length; i++) {
    Field field = fields[i];
    allFields.append(field.getName() + " - " + field.getModifiers());
}

(this code is part of functionality for checking if resources are intact)

I had this mechanism for some time, but now (after updating code to new API-Level 30) it stopped working. When I run application from Android Studio then fields are found and I can list them.

But when I build app and run .apk it on the same device then fields array is empty. App works normally and all resources are available for normal usage.

I tried unpacking .apk file and I found expected keys in apk/res/values/public.xml. I also inspected project and fixed all errors.

Was there some change in privacy for this fields (in API 29 or 30)? Why I cannot access this data?





Aucun commentaire:

Enregistrer un commentaire