Migrating Android project with proguard to R8, missing rt.java file, Android Studio 4.2
Asked Answered
N

3

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.

Naphtha answered 17/5, 2021 at 17:18 Comment(0)
S
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.

Statutable answered 18/5, 2021 at 6:20 Comment(6)
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.Naphtha
copying rt.jar from jdk8 isn't a viable solutionLycaonia
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.Statutable
@Statutable 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 <java.home>/lib/rt.jar, this could be the possible problem? I will try to delete it and see how it goesNaphtha
Yes, removing -libraryjars <java.home>/lib/rt.jar should be the right way to go. AGP will implicitly add the android.jar for the compile SDK as library path.Statutable
@Statutable you are right, removing that sentence from proguard-rules.pro solves the problem, now I'm able to use android studio 4.2.1Naphtha
E
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.

Ezekielezell answered 25/1, 2022 at 9:40 Comment(1)
This should be the accepted answerUngley
G
3

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

-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)
Goldfinch answered 2/8, 2022 at 16:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.