Got “unsupported class file version 52.0” after including a module to a project

前端 未结 4 760
轻奢々
轻奢々 2020-12-03 21:11

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

4条回答
  •  孤城傲影
    2020-12-03 21:28

    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
    }
    

提交回复
热议问题