修改AOSP框架代码构建自定义SDK后,Android Studio无法识别修改内容的求助
Hi there! It sounds like you've already made great progress modifying the AOSP framework and compiling the SDK—let's tackle why your custom requestPermissions method isn't showing up in Android Studio. The core issue here is that Android Studio relies on the SDK stub files (like android.jar) to provide API hints and auto-completion, and your new method hasn't been added to these stubs yet. Here's how to fix it step by step:
1. Update the Public API Signature List
AOSP maintains a list of all public APIs in frameworks/base/core/api/current.txt. Your new method won't be included in the SDK stubs unless it's added to this file.
- Run this command in your AOSP root directory to auto-detect and update the API list:
make update-api - Open
frameworks/base/core/api/current.txtand verify your method signature is present. It should look like this:
If it's not there, you can add it manually (just make sure the signature matches exactly what you wrote inpublic final void requestPermissions(java.lang.String[], int, java.lang.String, java.lang.String)Activity.java).
2. Recompile the SDK with Updated Stubs
Your initial SDK build used the old API stubs, so we need to rebuild from a clean state to ensure the new method is included:
. build/envsetup.sh lunch sdk_phone_x86 sdk-eng make clean-sdk # Clears cached stub files to avoid issues make -j16 sdk
3. Ensure Android Studio is Using the Updated SDK
Double-check that you've replaced the entire SDK directory in Android Studio, not just individual files:
- The compiled SDK is located in
out/host/linux-x86/sdk/sdk_phone_x86/(adjust the path if you're on macOS/Windows). - In Android Studio, go to
File > Project Structure > SDK Locationand confirm it points to your custom SDK folder. - In your test app's
build.gradle(Module level), make surecompileSdkVersionandtargetSdkVersionmatch the version of your custom SDK (e.g., if you built for Android 12, usecompileSdk 31).
4. Verify the Stub File Includes Your Method
To confirm the fix worked, check the android.jar in your custom SDK:
- Navigate to
platforms/android-XX/android.jar(replaceXXwith your SDK version). - Use a decompiler like JD-GUI to open the jar, then look for
android.app.Activity—your newrequestPermissionsoverload should be listed.
Quick Troubleshooting Tips
- Don't add
@hideto your method: This annotation excludes APIs from public stubs, which is why we're avoiding it here. - Test with a new project: Sometimes old project caches can cause issues—create a fresh Android project and try calling your custom method to see if auto-completion works.
内容的提问来源于stack exchange,提问作者Rashedur Rahman

