4

I searched other answers and I tried to find a solution, I know that This questions has been asked.

Suddenly my Android Studio cannot find R class (R.raw.blabla). Cannot find any R file

In other classes it's working.

What i tried :

  • Clean Project
  • Import manually R
  • Check Correct Package name in Manifest/Gradle applicationId
  • Clean from Gradle ( gradlew clean)
  • Rebuild (Gradle and from Tool window)
  • Invalidate Caches and Restart
  • Restart OS
  • Delete .gradle directory
  • Resync Gradle files with AS
  • Run Code Analysis and fix Any warnings/Errors
  • Go through whole xml files and search for bugs/typos
  • Re-import project
  • Update SDK tools/re-download
  • Update Build Tools
  • Update Dependencies
  • Delete .idea folder
  • Make Project, Make Module
  • Re install Android Studio
  • Download Latest Android Studio (Canary 3.3 Canary 11 Sept 15 2018)
  • Fix lint errors with Gradle (gradlew lintFix)
  • update Gradle wrapper
  • disable D8
  • enable D8
  • assemble
  • cleanBuildCache
  • Update Kotlin Version
  • Revert Kotlin Version from Dev (1.3-20M) to (to 1.2.70)
  • Partially remove every dependency and re add them one by one
  • Delete all sub project build folder, clean and re build
  • Revert From targetSDK/CompileSDK/BuildTools 28 to 27

Just 2 xml files still got error

-No other xml files modified i mean default values

<?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>
Sz-Nika Janos
  • 811
  • 6
  • 19
  • Issue only with R.raw or another too like R.id...? – Tapa Save Sep 25 '18 at 14:19
  • Any R. file. Sorry i updated. – Sz-Nika Janos Sep 25 '18 at 14:21
  • The R class is in the build folder. Try deleting that too, even though a clean should've done it. And when you do try building, does it error or build successfully? – TheWanderer Sep 25 '18 at 14:23
  • 1
    This typically happens if there is an error in one of the resource files. – Henry Sep 25 '18 at 14:25
  • @TheWanderer I deleted it, and build is successfully executed. – Sz-Nika Janos Sep 25 '18 at 14:31
  • @Henry I have 2 simple xml files, with TextView other are commented out for the purpose of testing the issue. – Sz-Nika Janos Sep 25 '18 at 14:31
  • XML commenting is unpredictable. Can you post exactly what you have in those XML files? – TheWanderer Sep 25 '18 at 14:32
  • Try next (crazy solution, but worked for me in past): 1. Remove all "implementation ..." lines in app.gradle files (of one half, then another half). 2. Sync now toast in AS. 3. Restore deleted lines in gradle files. 4. Sync now toast in AS again. – Tapa Save Sep 25 '18 at 14:33
  • 1
    Try to create a new project and copy-paste everything to it – lior_13 Sep 25 '18 at 14:38
  • lets say disable instant run, update gradle this time, this will complete the list. – bluetoothfx Sep 25 '18 at 15:13
  • @bluetoothfx i tried it but i forgot to mention it, finally i found the problem. It was a bug i think from Android Studio canary 3.11 I posted answer with my solution hope it helps others who might have the same problem as me – Sz-Nika Janos Sep 25 '18 at 19:07
  • Possible duplicate of ["cannot resolve symbol R" in Android Studio](https://stackoverflow.com/questions/17054000/cannot-resolve-symbol-r-in-android-studio) – Taslim Oseni Nov 03 '18 at 21:38
  • @Taslim as you can see i didn't use admob and also listed every other solution found on stackoverflow. – Sz-Nika Janos Nov 03 '18 at 22:32

1 Answers1

0

Actually i found a weird solution:

I tried to import project on a stable/beta Android Studio (3.2) from Canary (3.11 Sept 05 2018) On the stable/beta channel the R class is building successfully and i could import it. Finally as curiosity i reloaded the project in the Canary version. And all was working. But in the end i decided to remain on stable channel, and wait for RC releases.

Sz-Nika Janos
  • 811
  • 6
  • 19