I am building AOSP and want to add a new package/class com.example.MyClass
to Android framework. What I did is to add com/example/MyClass.java
under framework/base/core/java
and build the AOSP emulator. After emulator starts, my test app can use java.lang.Class.ForName("com.example.MyClass")
to load the class at run-time, but when trying to access a public static field MY_FIELD
of MyClass
, it threw a “NoSuchFieldException:MY_FIELD”. I also saw this in LogCat: Accessing hidden field Lcom/example/MyClass;->MY_FIELD:I (blocked, reflection, denied)
My test app can successfully get the fields in org.apache.http.conn.ssl.SSLSocketFactory
which is part of the Android frameworks, so I guess I missed some steps for com.example.MyClass
(like exposing it to app?). Can anyone point me the direction? Thanks!
I tried the following steps from this post, but is not working.
adb shell settings put global hidden_api_policy_pre_p_apps 1
adb shell settings put global hidden_api_policy_p_apps 1