日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【错误记录】Android 编译时技术版本警告 ( 注解处理器与主应用支持的 Java 版本不匹配 )

發布時間:2025/6/17 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【错误记录】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 版本不匹配 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。