I have an Android Studio project with a pure Java 8 library module. Here is the complete gradle.build file for that library:
apply plugin: 'java-library'
dependencies {
testImplementation 'junit:junit:4.12'
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
The code is tested and works fine.
The problem I am having is that I have built the project, and then tried to use the built .jar file in another Android project that doesn't uses Java 7 (not 8). Obviously, the code does not work. However, I am surprised that there are no compile-time errors indicating that the library is not compatible. Instead, I only first notice the incompatibility when a runtime function is called.
Am I doing something wrong in how I am compiling the Java module? Or is it expected behavior that you will only get runtime errors that the library is not compatible? I expected compile-time errors.
Also, please tell me how to compile properly so that I can get compile-time errors in Android Studio indicating that a library was compiled with a newer Java version.
For completeness, I am getting the following runtime error when I use my Java 8 library module
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Base64;