Reputation: 189
I needed to perform an update of my android app to update the targetSdkVersion from 29 to 31 (in a first step). In this context, I have updated my Android Studio from 4.0.2 to Android Studio Electric Eel | 2022.1.1. Additionally, I upgraded my Gradle from 6.x to 7.5 (Want to upgrade to 8 at a later stage).
After I performed the update, Android Studio does not find or generate the R class anymore. I get the error "Cannot resolve symbol 'R'" when I import the class with import my.package.R;
Anyhow, I am still able to successfully build my project and run it on an emulator. I also deployed the application on my phone and it works fine. I searched the internet for help and I found that the editor of Android Studio and the build function have different compilers which is why this probably works. However, how can I fix my problem with the editor?
This is what I already did:
Any help to fix this is appreciated. FYI: my gradle looks like this:
apply plugin: 'com.android.application'
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
android {
compileSdkVersion 31
defaultConfig {
applicationId "my.app.id"
versionCode versionMajor * 10000
+ versionMinor * 100
+ versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
minSdkVersion 26
targetSdkVersion 31
versionCode 4
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
debug {
versionNameSuffix ".debug"
resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix}"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "app_version", "${defaultConfig.versionName}"
}
}
namespace 'my.app.id'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '30.0.2'
}
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}
Upvotes: 0
Views: 147
Reputation: 9
step 1: clean
step 2: gradle sync
step 3: rebuild the project
If problem still exists try invalidateCache & Restart
Upvotes: 0