【问题标题】:AndroidManifest.xml "Unresolved package" ErrorAndroidManifest.xml“未解析的包”错误
【发布时间】:2021-12-29 16:49:21
【问题描述】:

我正在开发一个媒体播放器应用程序。我正在实现MediaButtonReceiver(用于控制来自耳机、蓝牙等外部设备的媒体输入)。

但是在 Android.xml 文件中声明接收器时,我遇到了这个错误,说 Unresolved package "media"

AndroidManifest.xml

错误

Unresolved package 'session'
Unresolved class 'MediaButtonReceiver'
Class referenced in the manifest, `com.example.android.MediaPlaybackService`, was not found in the project or the libraries
Unresolved package 'android'
Unresolved class 'MediaPlaybackService'

build.gradle:app

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.helloworld"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Android.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelloWorld">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name="android.support.v4.media.session.MediaButtonReceiver">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>
        <service android:name="com.example.android.MediaPlaybackService" >
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </service>
    </application>

</manifest>

【问题讨论】:

    标签: android gradle android-manifest android-mediaplayer media-buttons


    【解决方案1】:

    也许尝试在 AndroidManifest.xml 中声明它,就像文档中所说的(对于 AndroidX):

     <receiver android:name="androidx.media.session.MediaButtonReceiver" >
       <intent-filter>
         <action android:name="android.intent.action.MEDIA_BUTTON" />
       </intent-filter>
     </receiver>
    

    【讨论】:

    • 是的,我也尝试过使用 androidx,但引起了同样的未解决的包错误
    • 我认为可能有一些方法可以在 xml 中包含或导入这些文件
    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 2015-06-04
    • 2011-05-23
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 2018-08-22
    相关资源
    最近更新 更多