Wrong Java Compiler When Including a Java Module as Dependency in Android Studio

前端 未结 2 610
独厮守ぢ
独厮守ぢ 2021-01-04 06:49

I have a java module in my Android Studio project that is a dependency of an Android module. I am having problems on build with the following exception appearing.

         


        
相关标签:
2条回答
  • 2021-01-04 07:44

    So I have found the solution at this blog post.

    The trick is in your Java Library module's build.gradle file you need to include the following.

    apply plugin: 'java'
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    

    This will then work.

    0 讨论(0)
  • 2021-01-04 07:46

    Seems things have changed on newer versions of Gradle / Android Studio, so the above solution about selecting source compatibility alone may not suffice. Particularly for complex projects which have a mix of modules which apply more than the simple android plugin ( I have seen following three plugins used on modules of same project: 'android' , 'java' and 'android-library')

    You need to make sure that the following things are satisfied if source compatibility alone does not resolve your issue.

    1) For you modules which apply plugin: 'android' select the source compatibility inside your build.gradle:

    android {
    
          //... other sections.
    compileOptions {
    
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }
    

    2) Select Project Byte code version from: File -> Other Settings -> Default settings.

    project bytecode version

    3) Explicitly select the JDK environment: File -> Project Structure -> SDK location and set it to the JDK 7 folder.

    explicit JDK selection

    --Update: with the new Android Studio 1.2.x they changed the location where you can select the Java byteCode version to the following: File->Other Settings->Default Settings->Build , Executions Enviromnent-> Compiler.

    enter image description here

    0 讨论(0)
提交回复
热议问题