alexzaitsev / apk-dependency-graph

Android class dependency visualizer. This tool helps to visualize the current state of the project.
Apache License 2.0
751 stars 71 forks source link

Exception in thread "main" java.lang.UnsupportedClassVersionError #44

Closed Kostyshina closed 5 years ago

Kostyshina commented 5 years ago

Hi, thank you for your lib. I wanted to check my project with it but ./run.sh give that crash

$ ./run.sh /home/anduser/Andersen/Learning/Archit cture/app/build/outputs/apk/debug/app-debug.apk com.mvisample true
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: code/Main has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

I have compile oprions in build.gradle

compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

The same is occurring for other project also. I have tried to change JDK location in my Android Studio to not embeded one but with new build I get the same error

$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

I have also tried plugin for Android Studio, but after first graph generation (it was empty) now clicking on Generate Graph button make Android Studio to close itself

UPDATE Have checked it with version 0.1.3 and everything works fine (in 0.1.4 jar is missing so also working). Does it mean that to work with 0.1.5 version I need to decompile jar with 1.8 java ?

victorrattis commented 5 years ago

Root Cause Analysis: This issue happened because the java version used to compile code/Main (inside apk-dependency-graph.jar) class is greater than your java version, which is 1.8.0 or 52.

The version 0.1.3 and 0.1.4 were compiled on "52 - Java SE 8" and 0.1.5 was compiled on "53 - Java SE 9". Because of that, your tests worked well using 0.1.3 and 0.1.4.

@Kostyshina For fix this issue:

  1. You could update your java version to 1.9.0 (53) or higher; or
  2. You could compile apk-dependency-graph.jar on the version 1.8.0 (52) following the steps described in this link;

@alexzaitsev Would you like compile and release a new version of 0.1.5 on the Java version 1.8.0 (52)?

alexzaitsev commented 5 years ago

@victorrattis thanks for such deep and precise analysis. I'm not sure what to do. What do you think, is it possible that someone could run it against java 7 and get this crash again? Anyway, seems that we should point a java version for each release in the release notes.. Doesn't seem convenient and simple... But as a temporary solution perhaps it's better just to recompile with java 8.

@victorrattis what do you think?

alexzaitsev commented 5 years ago

@Kostyshina I have fixed the apk in 0.1.5 release. Could you check, please?