1

I'm developing an Android app which gets signed by the platform certificate. For testing purposes I'm using the Android Emulator with x86_64 AOSP image, API Level 27, Android 8.1.

The app wants to use a function that has been declared as hidden with the @hide annotation. As expected Android Studio 3.0 can't resolve the symbol.

I could use reflection, but since my app has the rights to use the internal functions, I try to avoid reflection.

How can I make Android Studio aware of the hidden functions ? I searched on SO and google, but couldn't find a suitable solution, only old ones (two years and older) that doesn't work (anymore). oat2dex method that doesn't work

Philip Zultan
  • 184
  • 1
  • 8
  • The obvious answer would be not to @hide it. What benefit is having that annotation actually giving you? – Gabe Sechan Sep 05 '18 at 14:37
  • The functions that I want to use and have the @hide annotation are from the Android SDK API not my own API. E.g. DevicePolicyManager.isSystemOnlyUser() – Philip Zultan Sep 06 '18 at 08:41

1 Answers1

1

You need to be building AOSP in order to force reveal these methods to Android Studio. You can remove the hide annotation in the .java files under framework, and then compile the sdk using the following lines,

lunch sdk-eng make update-api make sdk

Then resolve the lint errors as they come, the errors themselves will tell you ways in which you can resolve them. Once this is done, copy the generated sdk folder to the ".Android/sdk/platforms" directory and re-open Android Studio.

EDIT: Just adding that such apps based on a re-compiled sdk would not work on a normal sdk since those functions are not recognized by the normal sdk. So in a controlled environment, you can make it work.

SamT01
  • 125
  • 1
  • 14