[英]Android Studio - R class unknown after Android Studio Update
我需要执行我的 android 应用程序的更新,以将 targetSdkVersion 从 29 更新到 31(第一步)。 在这种情况下,我已将我的 Android Studio 从 4.0.2 更新到 Android Studio Electric Eel | 2022.1.1. 此外,我将我的 Gradle 从 6.x 升级到 7.5(稍后想升级到 8)。
在我执行更新后,Android Studio 不再找到或生成 R class。 使用import my.package.R;
无论如何,我仍然能够成功构建我的项目并在模拟器上运行它。 我还在我的手机上部署了应用程序,它运行良好。 我在 inte.net 上搜索帮助,发现 Android Studio 的编辑器和 function 版本有不同的编译器,这就是为什么这可能有效。 但是,如何解决编辑器的问题?
这是我已经做过的:
解决此问题的任何帮助表示赞赏。 仅供参考:我的 gradle 看起来像这样:
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'
}
step 1: clean
step 2: gradle sync
step 3: rebuild the project
如果问题仍然存在,请尝试invalidateCache & Restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.