Android项目编译报错:无法获取CompileOptions的javaVersion属性
Let's break down exactly what's going wrong here and how to fix it quickly:
Root Cause
Your error is a simple typo in your compileOptions block. Look at this line:
targetCompatibility javaVersion.VERSION_1_2
You used lowercase javaVersion instead of the correct uppercase JavaVersion (this is a Gradle enum class, so case matters!). Changing the version to VERSION_1_2 was unnecessary too—Android Studio 2.2.3 fully supports Java 8, which is what you originally intended to use.
Step-by-Step Fix
Replace your entire compileOptions block with this corrected code (we'll revert to Java 8 since that's the standard for Android development):
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
That's it! The typo is fixed, and you're back to using Java 8 which gives you access to modern language features like lambdas, default methods, etc.
Quick Check for Smooth Compilation
Just to make sure everything works seamlessly with your Android Studio 2.2.3 setup:
- Verify your project's root
build.gradleuses the matching Gradle plugin version:dependencies { classpath 'com.android.tools.build:gradle:2.2.3' // ... other classpaths like Google Services } - Your current
compileSdkVersion 25and Firebase/Play Services dependencies (version 11.0.1) are compatible, so no changes needed there.
内容的提问来源于stack exchange,提问作者Farrukh Mughal

