【错误记录】Android 编译时技术版本警告 ( 注解处理器与主应用支持的 Java 版本不匹配 )
生活随笔
收集整理的這篇文章主要介紹了
【错误记录】Android 编译时技术版本警告 ( 注解处理器与主应用支持的 Java 版本不匹配 )
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 一、報錯信息
- 二、問題分析
- 三、解決方案
一、報錯信息
在使用 Android 編譯時技術 , 涉及 編譯時注解 , 注解處理器 ;
開發注解處理器后 , 編譯報如下警告 ;
該警告不會影響編譯 , 也不會中斷編譯的進行 , 編譯依然能成功 ;
警告: 來自注釋處理程序 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' 的受支持 source 版本 'RELEASE_7' 低于 -source '1.8' 注: SupportedAnnotationTypes : kim.hsl.router_annotation.Route 1 個警告二、問題分析
在 Android 主應用的 build.gradle 構建腳本中 , 支持的 Java 版本是 1.8 ;
android {compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8} }在 編譯時注解 依賴庫 中的 build.gradle 構建腳本如下 :
plugins {id 'java-library' }java {sourceCompatibility = JavaVersion.VERSION_1_7targetCompatibility = JavaVersion.VERSION_1_7 }在注解處理器依賴庫 中的 build.gradle 構建腳本如下 :
plugins {id 'java-library' }java {sourceCompatibility = JavaVersion.VERSION_1_7targetCompatibility = JavaVersion.VERSION_1_7 }dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation project(path: ':router-annotation')annotationProcessor 'com.google.auto.service:auto-service:1.0-rc4'compileOnly 'com.google.auto.service:auto-service:1.0-rc4' }注解處理器上使用 @SupportedSourceVersion 注解設置的支持的 Java 版本號也是 1.7 ;
// 自動注冊注解處理器 @AutoService(Processor.class) // 支持的注解類型 @SupportedAnnotationTypes({"kim.hsl.router_annotation.Route"}) // 支持的 Java 版本 @SupportedSourceVersion(SourceVersion.RELEASE_7) public class RouterProcessor extends AbstractProcessor { }三、解決方案
將上述的 Java 版本號都設置為 1.8 ;
編譯時注解 依賴庫 的 build.gradle :
plugins {id 'java-library' }java {sourceCompatibility = JavaVersion.VERSION_1_8targetCompatibility = JavaVersion.VERSION_1_8 }注解處理器 依賴庫 的 build.gradle :
plugins {id 'java-library' }java {sourceCompatibility = JavaVersion.VERSION_1_8targetCompatibility = JavaVersion.VERSION_1_8 }dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation project(path: ':router-annotation')annotationProcessor 'com.google.auto.service:auto-service:1.0-rc4'compileOnly 'com.google.auto.service:auto-service:1.0-rc4' }注解處理器 支持的 Java 版本號 : @SupportedSourceVersion(SourceVersion.RELEASE_8) 支持到 1.8 ;
// 自動注冊注解處理器 @AutoService(Processor.class) // 支持的注解類型 @SupportedAnnotationTypes({"kim.hsl.router_annotation.Route"}) // 支持的 Java 版本 @SupportedSourceVersion(SourceVersion.RELEASE_8) public class RouterProcessor extends AbstractProcessor { }修改后 , 編譯時不再報上述警告 ;
總結
以上是生活随笔為你收集整理的【错误记录】Android 编译时技术版本警告 ( 注解处理器与主应用支持的 Java 版本不匹配 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android Gradle】安卓应用
- 下一篇: 【Android 组件化】路由组件 (