【Kotlin】library或compileSdkVersion版本錯誤

前言:

在寫完kotlin程式要運行時,出現了以下錯誤,從錯誤的訊息中看來是模組的版本錯誤,因此我上網找尋相關解決方法,並成功解決。

錯誤訊息:

6 issues were found when checking AAR metadata:

  1.  Dependency 'androidx.appcompat:appcompat-resources:1.6.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

  2.  Dependency 'androidx.appcompat:appcompat:1.6.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

  3.  Dependency 'androidx.activity:activity:1.6.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

  4.  Dependency 'androidx.core:core:1.9.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

  5.  Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

  6.  Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that

      depend on it to compile against version 33 or later of the

      Android APIs.

      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion

      of at least 33, for example 33.

      Note that updating a library or application's compileSdkVersion (which

      allows newer APIs to be used) can be done separately from updating

      targetSdkVersion (which opts the app in to new runtime behavior) and

      minSdkVersion (which determines which devices the app can be installed

      on).

從上述錯誤訊息中看起來是版本問題,而且錯誤訊息中也有提示解決方法為使用較新的compileSdkVersion。

解決方法:

我參考stackoverflow上的解決方法成功解決,解決方法如下:

步驟1:點選build.gradle

步驟2:找到   implementation ‘androidx.core:core-ktx:1.7.0’以及 implementation ‘androidx.appcompat:appcompat:1.6.0′(此處之版本數字可能不同),如下圖所示

步驟3:更改版本號為 implementation ‘androidx.core:core-ktx:1.8.0’以及 implementation ‘androidx.appcompat:appcompat:1.5.0’並按下同步(Sync Now)

步驟4:成功運行

Similar Posts