无法解析符号 'MediaSessionCompat'

Cannot resolve symbol 'MediaSessionCompat'

我无法导入 MediaSessionCompat。 用于导入整个 android.support.v4.media 库的导入语句不会出现在 Android Studio "IntelliSense" 中,并且它无法解析其中任何内容的符号。

我是否必须进行某种额外的配置才能获得此导入,例如在应用程序中 build.gradle

将这些添加到您的依赖项并同步 Gradle:


AndroidX 之前版本

implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'

Post-AndroidX

implementation 'androidx.core:core:1.3.1'
implementation 'androidx.media:media:1.2.0'

来自官方文档:

With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library. We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.

最新的依赖项是:

implementation 'androidx.core:core:1.1.0'
implementation 'androidx.media:media:1.1.0'