Android API 23 找不到平台的来源(Android Studio 2.0)

Sources for Android API 23 Platform not found (Android Studio 2.0)

Android Studio 没有正确地将我重定向到 API 来源。当我点击任何函数时,它会反编译 .class 文件字节码,而不是从 sdk/sources 树访问正确的文件。 点击 "download" 和 "refreshing" 选项什么都不做。这对于实现监听器来说特别烦人,因为它生成的函数头没有来自文档的变量鬃毛(即 var1、var2 等)。我已经安装了 API 23(SDK 平台、工具、文档、源代码)。我已将编译和目标 SDK 设置为 23。 我尝试重新安装 SDK 工具,从金丝雀通道更新 AS,使缓存无效,但到目前为止没有任何帮助。 我切换到 API 21 并且工作正常。

我错过了什么?

我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "com.myapp.app"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile project(':volley')
    compile 'com.jakewharton:butterknife:7.0.1'
}

您可以在下面找到具有相同 API 23 集和相同行为的空白项目(没有第 3 方库)的 gradle 输出。

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:clean
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library
:app:prepareComAndroidSupportAppcompatV72330Library
:app:prepareComAndroidSupportDesign2330Library
:app:prepareComAndroidSupportRecyclerviewV72330Library
:app:prepareComAndroidSupportSupportV42330Library
:app:prepareComAndroidSupportSupportVectorDrawable2330Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies

BUILD SUCCESSFUL

将您的 Android Studio 更新为 Api 23 前往:

Tools > Android > SDK Manager,

您可以转到 SDK Tools 选项卡或单击 Launch Sdandalone SDK Manager。检查 Android SDK Build-tools 23.0.2 安装

更新:

请从您的依赖项中删除:

compile project(':volley')

并将其替换为:

compile 'com.android.volley:volley:1.0.0'

对于面临相同问题的人,Windows 的解决方案在 this post for Linux and in the same topic here 中(感谢 Aamir Abro)。基本上,您必须为缺少的 API 级别编辑 jdk.table.xml 文件。我不知道为什么,但是 Android 2.0 和 2.1 RC 没有在 <sourcePath> 中填充 <root type="composite" />。我更新了来源的路径 <root type="simple" url="file://D:/android/sdk/sources/android-23" />,现在可以使用了。

对于 Windows 用户 file location: C:\Users{USER_NAME}.AndroidStudio2.0\config\options\jdk.table.xml

对于 Linux 用户 file location: ~/Library/Preferences/AndroidStudioBeta/options/jdk.table.xml

编辑:

对于某些人来说,重置 SDK 位置有帮助 source

显然这个问题已在 Android Studio 2.1 中得到修复。 在 Android Studio 中重新运行 Android SDK 管理器设置,这应该可以解决您的问题。

在 Android 工作室中:

Windows: 文件 -> 设置 (ctrl+alt+s) -> 外观和行为 -> 系统设置 -> AndroidSDK.

Mac: Android Studio -> 首选项 (cmd + ,) -> 外观和行为 -> 系统设置 -> Android SDK.

单击Android SDK 位置右侧的编辑。 在向导中一直单击 下一步,这应该可以解决问题。

有人回答了 here 另一个问题。

正如 在他的评论中提到的,重置 SDK 的路径为我们中的一些人解决了这个问题。

Solution:

Android Studio 2.1 reporting in: solved the issue by resetting SDK.

Preferences -> Appearance & Behavior -> System Settings -> Android SDK.

Click on Edit to the right of Android SDK location. Next, next, next to complete the wizard and voila!

API 28 级 Android Studio 3.2.1 在 Windows 10 上遇到了同样的问题。刷新无效。

重新启动 Android Studio 后有效。

有时会出现2个错误,第一个会说:'platform android 28 not found',点击下一步,'accept some license agreement...'。一旦您接受协议,这两个错误都会消失。