【问题标题】:Cannot Resolve R [No admob]无法解析 R [无 admob]
【发布时间】:2019-03-01 05:00:12
【问题描述】:

我搜索了其他答案并试图找到解决方案,我知道有人问过这个问题。

我的 Android Studio 突然找不到 R 类 (R.raw.blabla)。 找不到任何 R 文件

在其他类中它正在工作。

我尝试了什么:

  • 清理项目
  • 手动导入R
  • 在 Manifest/Gradle applicationId 中检查正确的包名称
  • 从 Gradle 中清理 (gradlew clean)
  • 重建(Gradle 和从工具窗口)
  • 使缓存无效并重新启动
  • 重启操作系统
  • 删除.gradle目录
  • 与 AS 重新同步 Gradle 文件
  • 运行代码分析并修复任何警告/错误
  • 浏览整个 xml 文件并搜索错误/错别字
  • 重新导入项目
  • 更新SDK工具/重新下载
  • 更新构建工具
  • 更新依赖关系
  • 删除 .idea 文件夹
  • 制作项目,制作模块
  • 重新安装 Android Studio
  • 下载最新的 Android Studio(Canary 3.3 Canary 2018 年 9 月 15 日 11 日)
  • 使用 Gradle 修复 lint 错误 (gradlew lintFix)
  • 更新 Gradle 包装器
  • 禁用 D8
  • 启用 D8
  • 组装
  • cleanBuildCache
  • 更新 Kotlin 版本
  • 将 Kotlin 版本从 Dev (1.3-20M) 恢复到(到 1.2.70)
  • 部分删除所有依赖项,然后一一重新添加
  • 删除所有子项目构建文件夹,清理并重新构建
  • 从 targetSDK/CompileSDK/BuildTools 28 恢复到 27

只有 2 个 xml 文件仍然有错误

-没有修改其他xml文件我的意思是默认值

<?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_constraint_layout">

<TextView
    android:id="@+id/month_textView"
    style="@style/textStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:text="Aug" />

<TextView
    android:id="@+id/dayNr_textView"
    style="@style/textStyle"

    app:layout_constraintEnd_toEndOf="@+id/month_textView"
    app:layout_constraintStart_toStartOf="@+id/month_textView"
    app:layout_constraintTop_toBottomOf="@+id/month_textView"
    tools:text="05" />

<TextView
    android:id="@+id/day_textView"
    style="@style/textStyle"

    app:layout_constraintEnd_toEndOf="@+id/dayNr_textView"
    app:layout_constraintStart_toStartOf="@+id/dayNr_textView"
    app:layout_constraintTop_toBottomOf="@+id/dayNr_textView"
    tools:text="Sun" />
  </android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 只有 R.raw 或其他类似 R.id 的问题...?
  • 任何 R. 文件。抱歉我更新了。
  • R 类在 build 文件夹中。尝试删除它,即使应该清理干净。当您尝试构建时,它会出错还是构建成功?
  • 如果其中一个资源文件出错,通常会发生这种情况。
  • 尝试创建一个新项目并将所有内容复制粘贴到其中

标签: android android-studio android-gradle-plugin android-build


【解决方案1】:

其实我找到了一个奇怪的解决方案:

我尝试从 Canary(2018 年 9 月 5 日 3.11 日)在稳定/测试版 Android Studio (3.2) 上导入项目 在稳定/测试版通道上,R 类正在成功构建,我可以导入它。 最后出于好奇,我在 Canary 版本中重新加载了项目。一切正常。 但最后我还是决定留在稳定频道,等待 RC 发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多