Android Error: package R does not exist


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