You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修改AOSP框架代码构建自定义SDK后,Android Studio无法识别修改内容的求助

Fixing Custom AOSP SDK Not Showing Up in 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.txt and verify your method signature is present. It should look like this:
    public final void requestPermissions(java.lang.String[], int, java.lang.String, java.lang.String)
    
    If it's not there, you can add it manually (just make sure the signature matches exactly what you wrote in 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 Location and confirm it points to your custom SDK folder.
  • In your test app's build.gradle (Module level), make sure compileSdkVersion and targetSdkVersion match the version of your custom SDK (e.g., if you built for Android 12, use compileSdk 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 (replace XX with your SDK version).
  • Use a decompiler like JD-GUI to open the jar, then look for android.app.Activity—your new requestPermissions overload should be listed.

Quick Troubleshooting Tips

  • Don't add @hide to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 14:37:39