Android Problem: Class file version 53

Alaa Alsalehi
4 min readDec 2, 2019

If you are not a geek, then you will miss this with area 51, definitely, you are in the wrong place. If you are a geek welcome in my article.

Introduction

Do you see this problem when you build your android app? This is like a nightmare to you, so I wrote this article to help you know more about this problem and how you can avoid it.

Java Background

Java as a language was a revolutionary language when it starts. One of the main points that java advanced over other languages was portability: compile once run everywhere. To implement portability, java needs to have a layer -between software and OS- hiding the complexity of every OS and wrapping its way for user machine resources with one single API. That layer called virtual machine VM. The virtual machine has a different implementation for different OS. VM does not run binary code it had its own code style called bytecode. And because Java as a language had a lot of enhancement and core modifications, this bytecode has different versions. Here you can find the famous bytecode versions with its related JDK.

Problem

As you notice version 53 is JDK 9 OK, but why I see this message as an error to my app? Simply because android does not support java after java 8 which is version 52. Still, I do not know why I see this message if android does not support Java 9. Most of the time you see this message because you are using a dependency compiled with java 9. Also why I see that I use dependency for android why it has that problem? Because Gradle is a building system not special for android apps only it also can build any java web application or desktop.

Solution

First, you need to detect which library has the problem it looks like a simple task you can know it with the last library added to your Gradle file. But it is not that simple, Gradle is a hierarchical building system and every library depends on other libraries. Sometimes you can simply remove the last added library, but other times this library is a core function on your app like a payment gateway library. OK someone says you can downgrade the library, but this is not an option in some situations, because you need to be up to date with some libraries to solve some issues or adding new important features. So you need to know what is the right library which has the problem.

Steps

1- Check the class had the error on your build that was on my situation

2- Search for that class to find the library has it -on my situation it was org.bouncycastle-

3- Check what is the exact version used from this library in this path “USER_HOME\.gradle\caches\modules-2\files-2.1\PACKAGE_NAME” also you can see resolved dependencies on right side of project structure screen

project structure window
Project Structure on android studio

do not depend on what is written on your Gradle file.

3- Simply you can replace this version with older once by the following technique

Exclude this package from the dependency you use -this will crash your app on every time this library called- so you need to add this library implicitly with a different version

implementation(‘com.stripe:stripe-android:12.1.0’){

exclude group: ‘org.bouncycastle’

}

implementation (group: ‘org.bouncycastle’, name: ‘bcprov-jdk15on’, version: ‘1.60’)

Do not use “transitive” because it will ignore all the dependencies on your library, we just need to exclude one package only

Caution: this is a great solution if you upgrade this library or moving it to branch with android support, but if you downgrade the library that may create a problem because of missing classes or methods.

Conclusion

Java is a very rich language with dozens of libraries and Gradle really is a flexible tool. Sometimes this great diversity in java libraries ended with problems like this one. The best solution is to report it to the creators, but if that does not an option this solution will help you a lot.

About Me

I’m Alaa Alsalehi a professional backend & mobile developer. I have a food recipe content startup with more than a quarter of a million active users.

📝 Read this story later in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--

Alaa Alsalehi

Chief technology officer of NewHR company, one of the leading companies in HR software in Palestine. I have a food recipe content startup