An error occurred while referencing the Java Library in the Android Studio2.1.2 Java 8 environment. studio2.1.2java8

Source: Internet
Author: User

An error occurred while referencing the Java Library in the Android Studio2.1.2 Java 8 environment. studio2.1.2java8

Problem: In the Android Studio2.1.2 + Java8 environment, the Java Library is referenced, and dataBinding is in the enable State, which may cause compilation errors, as shown in:

Solution:

1. Add the following code to the build. gradle file of all modules:

android {    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_7        targetCompatibility JavaVersion.VERSION_1_7    }}

Re-compile and run the program and find that the same error is still reported, so you must modify other places.

2. If you think it is not feasible to set the Java version to 1.7, you can directly change the version to 1.8.

android {    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }}

If an error is returned, set Jack to enable as follows:

I have Baidu data on the Internet, modify the build. gradle file of the main module, and add the code

defaultConfig {    jackOptions {        enabled true    }}

Compile again and find that my situation is really special. I still reported an error because I used databinding,

3. Finally, I modified it back and set the Java version to 1.7. set the Java version in the gradle file, and build in the referenced Java Library. the following is added to the gradle file:

"SourceCompatibility = '1. 7'" and "targetCompatibility = '1. 7'", the Code is as follows:
apply plugin: 'java'dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    sourceCompatibility = '1.7'    targetCompatibility = '1.7'}

Finally, the compilation is successful.

Follow-up: Of course, you can install Java1.7 and Java1.8 at the same time on the Internet. I personally think it is quite troublesome to install the two versions, so it is easier to configure them.

Summary:

Some functions are not supported in the Java 1.8 environment. It is best to choose stable and mature when installing and configuring the environment.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.