2025-09-04

紀錄一下自己接手一個 android app 時遇到的問題

我接手一個 android app,他有使用一個 lib:PageIndicatorview

dependencies {
        implementation 'com.romandanylyk:pageindicatorview:1.0.2'
}

執行 gradlew.bat assembleDebug --warning-mode all 後,會回復以下 2 個錯誤訊息

The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 9.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/8.10.2/userguide/upgrading_version_6.html#jcenter_deprecation
        at build_c0uup8fmroz422c6id7ruwe51$_run_closure1$_closure2.doCall$original(D:\workspace\app\build.gradle:4)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
        at build_c0uup8fmroz422c6id7ruwe51$_run_closure1.doCall$original(D:\workspace\app\build.gradle:2)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
WARNING: The option setting 'android.defaults.buildfeatures.buildconfig=true' is deprecated.
The current default is 'false'.
It will be removed in version 9.0 of the Android Gradle plugin.
To keep using this feature, add the following to your module-level build.gradle files:
    android.buildFeatures.buildConfig = true
or from Android Studio, click: `Refactor` > `Migrate BuildConfig to Gradle Build Files`.
> Task :app:checkDebugAarMetadata FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.romandanylyk:pageindicatorview:1.0.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/github/romandanylyk/PageIndicatorView/v1.0.2/PageIndicatorView-v1.0.2.pom
       - https://repo.maven.apache.org/maven2/com/github/romandanylyk/PageIndicatorView/v1.0.2/PageIndicatorView-v1.0.2.pom
       - https://jitpack.io/com/github/romandanylyk/PageIndicatorView/v1.0.2/PageIndicatorView-v1.0.2.pom
     Required by:
         project :app

這邊記錄這兩個問題如何解決

The RepositoryHandler.jcenter() method has been deprecated

首先是第一個問題

第一個問題很好解決,把 {專案資料夾}/build.gradle{專案資料夾}/app/build.gradle 裡面的 jcenter() 改成 mavenCentral() 就可以解決了

Could not find com.romandanylyk:pageindicatorview:1.0.2.

第二個問題比較麻煩了

這是因為在 maven 那找不到這個 library

實際上直接去 maven 官網(https://mvnrepository.com/artifact/com.romandanylyk/pageindicatorview),雖然有提供 1.0.2版與 1.0.3版,但這些的超連結都已死

最後詢問了 AI 得到解答

解決方法

首先在{專案資料夾}/build.gradle追加 library 的來源

原本是

allprojects {
	repositories {
		google()
		mavenCentral() // 這邊因為第一步的關係,不會是 jcenter() 
	}
}

改成

allprojects {
	repositories {
		google()
		mavenCentral()  
		maven { url 'https://jitpack.io' } 
	}
}

然後去 jitpack 找 pageindicatorview 這 library

根據上面的資訊,修改 gradle 即可

dependencies {
        implementation 'com.github.romandanylyk:PageIndicatorView:v1.0.1'
}

沒有留言:

張貼留言