Search code examples
javaandroidxmlandroid-studiojar

Android Studio - Java - "Invalid or corrupt jarfile" ...\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar


In my Android Studio java app - error upon running the app:

"C:\Program Files\Android\Android Studio\jbr\bin\java.exe" -Dfile.encoding=windows-1252 -jar "D:\work\Android Studio\SongTracker\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar"
Error: Invalid or corrupt jarfile D:\work\Android Studio\SongTracker\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar

Process finished with exit code 1

The problem started after adjusting xml code - working with a RecyclerView inside a NestedScrollView - originally ran into error about not being able to find a @mipmap/ic_launcher file, then morphed into something like this:

Unable to delete directory 'D:\work\Android Studio\SongTracker\app\build'
  Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.

In doing research found one 'fix' to edit the R.jar file by running in the terminal window: unzip R.jar and jar -xf R.jar which might have escalated the problem. It seemed to do nothing however the problem continues to escallate into something I cannot solve all related to my R.jar file.

Here are some of the attempts to rectify the situation - NONE of these made any difference:

  1. deleted R.jar and rebuilt
  2. ran taskkill /im java.exe /f
  3. tried Clean Project then Rebuild Project - both processes completed without any errors
  4. File -> Invalidate Caches / Restart in Android Studio
  5. restarted computer to clear any file locks
  6. Tried reverting my xml changes temporarily to isolate the issue
  7. Manually deleted the app/build directory, then Cleaned and Rebuilt project
  8. Tried killing adb.exe (which shows as adb (32bit) in task manager) from task manager - thanks @General Tony for the suggestion!

Here is the Application portion of my AndroidManifest.xml:

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.SongTracker"
        tools:targetApi="31">

I notice a R.jar dropdown menu at the top of my AS desktop - not sure if this was always there and I never noticed or if this is a prompt for further action, here is what I am seeing:

enter image description here

Thank you in advance for any feedback or insight that you can offer.

best


Solution

  • Still not exactly sure how I got into this but getting out turned out, at least in my case to be very simple.

    In the R.jar drop down menu I selected the Run Configurations option for the app: Clicked here to solve

    This was the solution, again for me, after running the configurations the R.jar drop down was replaced by the app drop down. I am now able to run the app without problem.