8

I update my Android Studio version from 4.1 to 4.2 and the project is not compiling because the Proguard version was very old (4.7) and it was not compatible with Java 10, however I decided to migrate my project from proguard to R8, but the project is not compiling because of this error:

File not found: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/lib/rt.jar

Then I set R8 to false and use Proguard adding this line to my build.gradle in order to update my Proguard to a higher version:

classpath 'net.sf.proguard:proguard-gradle:6.1.1'

But still, I got the same error and not the first one that was telling me to update a newer version of Proguard.

So how I can fix that rt.jar? Maybe some directory change from one AS version and the other?, If I downgrade my android studio to 4.1 and revert all the changes that I did, the project works fine, but I want to upgrade Android Studio.

dicarlomagnus
  • 576
  • 4
  • 17

3 Answers3

4

Starting from JDK 9 there rt.jar is not longer part of the JDK, see Removed rt.jar and tools.jar in JDK 9 for details.

In most cases if rt.jar was required for compilation before an rt.jar from JDK 8 should work.

However, what is the reason for using rt.jar on an Android project? Normally the android.jar supplied by Android Studio/AGP when shrinking should work.

sgjesse
  • 3,793
  • 14
  • 17
  • Hi, thanks for answering, actually I don't know what AS needs this, this problem is happening just for Android studio 4.2, I opened my project on Android 4.1 then I enabled R8 and the project was compiling well on that version, but if I update AS to 4.2 I get this error of the rt.jar file not found. But haven't found a solution yet. – dicarlomagnus May 18 '21 at 19:55
  • copying rt.jar from jdk8 isn't a viable solution – Zayin Krige May 20 '21 at 07:33
  • 2
    The first thing to do is to find where the reference to `rt.jar` is in you configuration. Normally an AS project will not have a reference to `rt.jar`, so it must have been added to the project configuration somehow. – sgjesse May 25 '21 at 06:25
  • @sgjesse on the project file: proguard-rules.pro I have this sentence, that's is the only pice on the whole project where the rt.jar is named: -libraryjars /lib/rt.jar, this could be the possible problem? I will try to delete it and see how it goes – dicarlomagnus May 25 '21 at 19:32
  • 5
    Yes, removing `-libraryjars /lib/rt.jar` should be the right way to go. AGP will implicitly add the `android.jar` for the compile SDK as library path. – sgjesse May 27 '21 at 11:48
  • @sgjesse you are right, removing that sentence from proguard-rules.pro solves the problem, now I'm able to use android studio 4.2.1 – dicarlomagnus Jun 14 '21 at 14:17
4

removing -libraryjars <java.home>/lib/rt.jar from proguard.txt should be the right way to go

mentioned by @sgjesse as a comment , that should be marked in answer.

applicable only after java version 8.

AMD
  • 1,662
  • 18
  • 39
2

There was a clause like this in the Proguard configuration, removing this solves the issue

-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428