Open Dev4Mod opened 1 month ago
This seems to be a long standing issue: https://github.com/mockito/mockito/issues/2302
Not sure if this can be avoided as it seems to be a security setting. Could you experiment a bit? I am not much into Android these days, but I am happy to merge a solution.
I used trusted as false because it is not necessary for the dex in classloader to have access to restricted APIs and this solved my problem without any
addDexPath.invoke(classLoader, jar.getAbsolutePath(), false);
In the excerpt about @UnsupportedAppUsage
/*
* This annotation indicates that you may be able to access the member at runtime, but that
* this access is discouraged and not supported by Android. If there is a value
* for {@link #maxTargetSdk()} on the annotation, access will be restricted based
* on the {@code targetSdkVersion} value set in your manifest.
*/
As addDexPath only has the annotation without maxTargetSdk there will be no problems using it.
https://github.com/raphw/byte-buddy/blob/12baac491ae4e103e641aca17981435b03484919/byte-buddy-android/src/main/java/net/bytebuddy/android/AndroidClassLoadingStrategy.java#L894
This is causing the error "java.lang.SecurityException: Can't exempt class, process is not debuggable." in applications that do not have the debuggable flag.
Exemple code: