无法解析符号'MediaSessionCompat'

24

我无法导入MediaSessionCompat

导入整个android.support.v4.media库的导入语句未出现在Android Studio“IntelliSense”中,并且它无法解析其中任何内容的符号。

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

3个回答

63

将以下内容添加到您的依赖项并同步Gradle:


AndroidX之前

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

AndroidX后

implementation 'androidx.core:core:1.8.0'
implementation 'androidx.media:media:1.6.0'

官方文档中的注意事项:

自Android 9.0(API级别28)发布以来,有一个名为AndroidX的支持库的新版本,它是Jetpack的一部分。 AndroidX库包含现有的支持库,并包括最新的Jetpack组件。 您可以继续使用支持库。历史构件(那些版本为27及更早版本,并打包为android.support.*)将继续在Google Maven上提供。但是,所有新的库开发都将在AndroidX库中进行。 我们建议在所有新项目中使用AndroidX库。您还应考虑将现有项目迁移到AndroidX。


1
最新的依赖项截至(2020年9月30日)为:implementation 'androidx.core:core:1.3.1' 和 implementation 'androidx.media:media:1.2.0' - Kenny Dabiri

16

最新的依赖关系为:

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

1
最新的依赖项截至(2020年9月30日)为:implementation 'androidx.core:core:1.3.1' 和 implementation 'androidx.media:media:1.2.0' - Kenny Dabiri

0
 def core_version = "1.9.0"

// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"

implementation "androidx.media:media:1.6.0"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接