Android Error: package R does not exist

Asked on July 10, 2023
I am creating Android application. In my Android Studio, when I build my application, I am getting error as

package R does not exist

How to fix it?

Replied on July 10, 2023

In Android application, R class is auto-generated by XML files. If there are error in your XML files in res directory, R class will not be created.

You need to check following files in your Android application.

1. Check for error in all your XML files in res directory such as  layout, menu etc.

2. Check for error in AndroidManifest.xml

3. Check for correct package in build.gradle file. The namespace and applicationId should match your package.

If your package is com.example.myapp, the namespace and applicationId should be as following

// build.gradle

namespace 'com.example.myapp'

compileSdk 33

defaultConfig {

    applicationId "com.example.myapp"

    minSdk 29

    targetSdk 33

    versionCode 1

    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


Replied on July 10, 2023
Thanks. Working.

Write Answer

©2024 | Privacy Policy | Contact Us