一、報(bào)錯(cuò)信息
編譯 Android Studio 項(xiàng)目時(shí) , 報(bào)如下錯(cuò)誤 , 下載依賴庫失敗 ;
報(bào)錯(cuò)信息 :
Execution failed for task ':ijkplayer-exo:generateDebugRFile'.
> Could not resolve all files for configuration ':ijkplayer-exo:debugCompileClasspath'.
> Could not resolve com.google.android.exoplayer:exoplayer:r1.5.11.
Required by:
project :ijkplayer-exo
> Could not resolve com.google.android.exoplayer:exoplayer:r1.5.11.
> Could not get resource 'https://raw.githubusercontent.com/Pgyer/analytics/master/com/google/android/exoplayer/exoplayer/r1.5.11/exoplayer-r1.5.11.pom'.
> Could not HEAD 'https://raw.githubusercontent.com/Pgyer/analytics/master/com/google/android/exoplayer/exoplayer/r1.5.11/exoplayer-r1.5.11.pom'.
> raw.githubusercontent.com
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
二、解決方案
1、確定 Maven 倉庫地址
下面是 當(dāng)前 Android 項(xiàng)目的 Gradle 配置中的 Maven 倉庫 ;
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
// ijkplayer 倉庫
maven { url "https://repo.spring.io/plugins-release/" }
maven { url "https://repository.mulesoft.org/nexus/content/repositories/public/" }
maven { url "https://dl.bintray.com/bilibili/maven/" }
}
}
其中使用 maven { url "https://repo.spring.io/plugins-release/" }
配置的 Maven 倉庫就是對(duì)應(yīng)的地址 ;
使用 google()
函數(shù)配置的 Maven 倉庫地址 是 https://maven.google.com/ , 可以通過 https://maven.google.com/web/index.html 地址搜索對(duì)應(yīng)的 依賴庫 ;
使用 mavenCentral()
函數(shù)配置的 Maven 倉庫地址是 https://repo1.maven.org/ ;
使用 jcenter()
函數(shù)配置的 Maven 倉庫地址是 http://jcenter.bintray.com , 目前已經(jīng)無法訪問 , 其依賴庫都遷移到了 Maven 中央倉庫 ;
2、構(gòu)建 Maven 依賴下載路徑
以 下載 org.springframework.boot:spring-boot-starter-web:2.5.0 為例 ,
- 組織ID 是 org.springframework.boot , 其對(duì)應(yīng)的路徑是 org/springframework/boot/ ;
- 構(gòu)件ID 是 spring-boot-starter-web ;
- 版本號(hào) 是 2.5.0 ;
下載路徑公式是 : 倉庫地址/組織ID/構(gòu)件ID/版本號(hào)/構(gòu)件ID-版本號(hào).jar ;
倉庫地址是 https://repo1.maven.org/maven2/ 地址 ;
按照上面的公式拼接起來就是 https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-web/2.5.0/spring-boot-starter-web-2.5.0.jar ;
將拼接的 https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-web/2.5.0/spring-boot-starter-web-2.5.0.jar 地址拷貝到瀏覽器中 , 就可以下載該 依賴庫 ;
下載完成后的文件如下 :
建議使用 wget 或者 curl 命令行工具下載 ;
3、檢查依賴庫是否存在
通過上述 Maven 倉庫依賴庫地址拼接 , 就可以知道 該 依賴庫是否在 Maven 倉庫中存在 , 如果存在就可以下載 , 如果不存在 , 則下載失敗 ;
到 Maven 倉庫中 對(duì)應(yīng)的地址 , 查找對(duì)應(yīng)的依賴庫 ;
如 : Maven 中央倉庫 , 使用 mavenCentral()
配置 ;
allprojects {
repositories {
mavenCentral()
}
}
對(duì)應(yīng)的地址是 https://repo1.maven.org/maven2/ , 進(jìn)入該頁面后 , 顯示的內(nèi)容如下 :
按照路徑查找 com.google.android.exoplayer:exoplayer:r1.5.11 依賴庫 ;
找到 https://repo1.maven.org/maven2/com/google/android/ 層級(jí) , 就沒有對(duì)應(yīng)的依賴庫了 , 說明在 Maven 中央倉庫 https://repo1.maven.org/maven2/ 中沒有 com.google.android.exoplayer:exoplayer 依賴庫 ;
文章來源:http://www.zghlxwxcb.cn/news/detail-852005.html
4、在 Gradle 中配置本地依賴
下載到本地后 , 將 下載的 依賴庫拷貝到本地路徑中 , 然后將相對(duì)路徑配置到 dependencies / implementation 依賴中 ;文章來源地址http://www.zghlxwxcb.cn/news/detail-852005.html
dependencies {
implementation files('path/to/your/downloaded/dependency.jar')
}
到了這里,關(guān)于【錯(cuò)誤記錄】Android 編譯報(bào)錯(cuò) ( Could not resolve xxx | 手動(dòng)下載依賴庫并進(jìn)行本地配置 Gradle 依賴的解決方案 | 構(gòu)建 Maven 依賴下載路徑 )的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!