Fardeen Khan
Fardeen Khan

Reputation: 55

AndroidManifest.xml "Unresolved package" Error

I am developing a Media Player app. I was implementing MediaButtonReceiver (which is used to control Media inputs given from Headphone, bluetooth like external devices).

But while declaring receiver in the manifest file I encountered a number of errors.

Errors:

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'
}

AndroidManifest.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>

Upvotes: 0

Views: 844

Answers (2)

Ray Chakrit
Ray Chakrit

Reputation: 480

"Unresolved package/reference" means that the supporting library doesn't exist. According to the bewildering Android dev doc, you must download it by adding the following code to Gradle Scripts > build.gradle (Module: xxx.app) inside dependencies{}, resync and the error will disappear from androidx.media.session.MediaButtonReceiver

implementation("androidx.media:media:1.6.0")

and add this code for the error to disappear from android.support.v4.media.session.MediaButtonReceiver

implementation("com.android.support:support-media-compat:28.0.0")

Check latest version of androidx and v4

Upvotes: 2

Alexy
Alexy

Reputation: 39

Maybe try to declare it in AndroidManifest.xml like the documentation said (for AndroidX) :

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

Upvotes: 0

Related Questions