After creating an empty project within Android Studio and including a pure java module, which compiles and works perfectly on its own, I get the following error on every sin
I got this error for the first time after updating Android Studio from 2.1 to 2.2.2, and was puzzled because my system only had Java 1.7 installed, or so I thought. It turns out Android 2.2.2 installs its own Java 1.8 JRE (C:\Program Files\Android\Android Studio\jre), thus the need to specify sourceCompatibility and targetCompatibility in the build.gradle for pure java libraries as explained above.
apply plugin: 'java'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
sourceCompatibility = 1.7
targetCompatibility = 1.7
}