Android Studio:如何附加 Android SDK 源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21221679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio: how to attach Android SDK sources?
提问by Lukas Fryc
How can I attach Android SDK sources to Android Studio?
如何将 Android SDK 源附加到 Android Studio?
When I open one of the Android classes, the "Sources not found" window with "Attach Sources" option doesn't appear.
当我打开其中一个 Android 类时,没有出现带有“附加源”选项的“未找到源”窗口。
What is the other way to do this?
这样做的另一种方法是什么?
采纳答案by pyus13
Open your sdk manager from toolbar menus and download the "Sources for Android SDK" for the API level defined in your build.gradle file like
从工具栏菜单打开您的 sdk 管理器,并下载 build.gradle 文件中定义的 API 级别的“Android SDK 源”,例如
compileSdkVersion 19 // compile with API level 19
Nothing else needs to be done.
没有其他事情需要做。
Note :Sources for SDK is available only for API levels 14 and above.
注意:SDK 源仅适用于 API 级别 14 及以上。
UPDATE ( Based on stable release 3.2.1):
更新(基于稳定版本 3.2.1):
Google changes the approach of shipping the sources, so lets see what changed.
谷歌改变了发送源的方法,让我们看看发生了什么变化。
Go to the following location
前往以下地点
Preferences -> Apperance & Behaviour -> System Settings -> Android SDK
Quite lazy to navigate type SDK
in search and studio will help you to take to right place.
SDK
在搜索和工作室中导航类型非常懒惰,将帮助您找到正确的位置。
You can read the description, says mostly what to do. So after clicking on "show package details" you will see whether sources are installed or not (as shown in below picture) if it is not installed do install and you are good.
您可以阅读说明,主要说明要做什么。所以点击“显示包详细信息”后,您将看到是否安装了源代码(如下图所示),如果没有安装,请安装,您很好。
回答by Alexander Mayatsky
Android Studio 3.2.1 reporting in: solved the issue by resetting SDK.
Android Studio 3.2.1 报告:通过重置 SDK 解决了该问题。
Preferences -> Appearance & Behavior -> System Settings -> Android SDK.
首选项 -> 外观和行为 -> 系统设置 -> Android SDK。
Click on Editto the right of Android SDK location. Next, Next, Finishto complete the wizard and voila!
单击Android SDK 位置右侧的编辑。 Next, Next, Finish完成向导,瞧!
回答by gdawg
I'm unable to find the aforementioned gui options in v8.11 on osx however grep-futells me:
我无法在 osx 上的 v8.11 中找到上述 gui 选项,但是grep-fu告诉我:
config is stored in ~/Library/Preferences/AndroidStudioBeta/options/jdk.table.xml
配置存储在~/Library/Preferences/AndroidStudioBeta/options/jdk.table.xml
After editing this file (with Studio stopped) and restarting source mapping works fine for me.
编辑此文件后(停止 Studio)并重新启动源映射对我来说效果很好。
diff --git a/options/jdk.table.xml b/options/jdk.table.xml
index 0112b91..33828b8 100644
--- a/options/jdk.table.xml
+++ b/options/jdk.table.xml
@@ -76,7 +76,7 @@
</javadocPath>
<sourcePath>
<root type="composite">
- <root type="simple" url="file:///Applications/Android Studio.app/sdk/sources/android-19" />
+ <root type="simple" url="file:///Users/tehdawgz/dev/android-sdk/sources/android-19" />
</root>
</sourcePath>
</roots>
回答by joshkendrick
For me on 2016/08/29 running android studio 2.1.3:
对于我在 2016/08/29 运行 android studio 2.1.3:
I had downloaded and was compiling against api 24 before the sources were released. I want to point at the source now that they've been released. Restarting Android Studio after downloading the sources in the SDK manager wasnt working.
在源代码发布之前,我已经下载并正在针对 api 24 进行编译。既然它们已经发布,我想指出来源。在 SDK 管理器中下载源代码后重新启动 Android Studio 不起作用。
I had to act like I was going to Edit the SDK location in the SDK Manager, when I did that, I could just click 'next' through the dialog and re-indexed the sdk stuff automatically.
我必须表现得好像我要在 SDK 管理器中编辑 SDK 位置,当我这样做时,我可以通过对话框单击“下一步”并自动重新索引 sdk 内容。
回答by urps
gdawg's solution worked for me as well in Windows 10 and Android Studio 2.0. With the small modification that the jdk.table.xml file is located at
gdawg 的解决方案在 Windows 10 和 Android Studio 2.0 中也适用于我。通过 jdk.table.xml 文件所在的小修改
C:\Users\{USER_NAME}\.AndroidStudio2.0\config\options\jdk.table.xml
C:\Users\{USER_NAME}\.AndroidStudio2.0\config\options\jdk.table.xml
回答by sfridman
Not sure why the accepted answer only seems to work with API level 19. I was able to attach SDK sources for API level 15 by explicitly providing the source path for the SDK. Here's what I did:
不知道为什么接受的答案似乎只适用于 API 级别 19。我能够通过显式提供 SDK 的源路径来附加 API 级别 15 的 SDK 源。这是我所做的:
- Make sure I've downloaded the desired SDK sources and setup my build.gradle with the desired API level.
- In the Project window on the left, select the External Libraries drop-down.
- Right click the menu item and select Open Library Settings.
- Click the Sourcepath tab and use the + icon at the bottom left to link to the desired SDK sources (should be in something/sdk/sources)
- 确保我已下载所需的 SDK 源并使用所需的 API 级别设置我的 build.gradle。
- 在左侧的 Project 窗口中,选择 External Libraries 下拉菜单。
- 右键单击菜单项并选择打开库设置。
- 单击 Sourcepath 选项卡并使用左下角的 + 图标链接到所需的 SDK 源(应该在 something/sdk/sources 中)
回答by clevertension
In android studio 0.8.6(Beta) (OSX 10.9.4), it seems that you can view the android source code directly without attaching the Sources manually.
在 android studio 0.8.6(Beta) (OSX 10.9.4) 中,似乎可以直接查看 android 源代码,而无需手动附加源。
The prerequisite is you should download "Sources for Android SDK" in "SDK Manager" and restart "Android Studio"
先决条件是您应该在“SDK Manager”中下载“Sources for Android SDK”并重新启动“Android Studio”
回答by DysaniazzZ
Just follow these steps: Settings --> Android SDK --> Launch Standalone SDK Manager --> download your needed SDK sources(in every Anroid Version's Sources for Android SDK
) --> restart your Android Studio. If above don't help, make sure you have downloaded the required SDK sources, and reset the Android SDK Location
to refresh. I hope it helps.
只需按照以下步骤操作:设置 --> Android SDK --> 启动独立 SDK 管理器 --> 下载您需要的 SDK 源(在每个 Anroid 版本中Sources for Android SDK
)--> 重新启动您的 Android Studio。如果以上没有帮助,请确保您已下载所需的 SDK 源,并将 重置Android SDK Location
为刷新。我希望它有帮助。
回答by user1364368
In Android Studio 2.3.3on Windows 7, I had the problem that the already downloaded source files für API-Level 26 in folder SDK\sources\android-26
were not recognized. Using "File | Invalidate Caches / Restart"solved the issue for me.
在Windows 7 上的Android Studio 2.3.3 中,我遇到了SDK\sources\android-26
无法识别文件夹中已下载的 API-Level 26 源文件的问题。使用“文件|无效缓存/重新启动”为我解决了这个问题。
回答by user4057066
For me downloading and refresh was not helping. I tried to choose source but still same issue. So I did Invalidate Cache/Restart. Now its working.
对我来说,下载和刷新没有帮助。我试图选择来源,但仍然是同样的问题。所以我做了无效缓存/重启。现在它的工作。
I tried to edit the jdk.table.xml file but there was no entry for android-26, it was only till android-25, so i decided not to edit that file.
我试图编辑 jdk.table.xml 文件,但没有 android-26 的条目,直到 android-25,所以我决定不编辑该文件。