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.