![](/img/trans.png)
[英]How to resolve 'com.android.support:appcompat-v7:28.0.0'
[英]Could not resolve com.android.support:appcompat-v7:28.0.0
關於這個有很多不同的問題,但是有關使用v7.28.0
, v7.28.+
, v7.28.0.0-rc02
但是當我同步我的項目時,我得到這個錯誤:
無法解析':app @ debug / compileClasspath'的依賴關系:無法解析com.android.support:appcompat-v7:28.0.0。
我已經檢查了支持庫設置並遵循了它的說明,但它沒有幫助。
這是我的模塊應用程序
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 8
versionName "1.6.3"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
和項目gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
android studio互聯網連接很好,因為我在設置中進行了測試,我不知道還有什么去看。
我甚至在AS 3.2.1中創建了一個新項目但是我得到了同樣的錯誤。 我不知道為什么每次更新AS時都會發生這種情況 !
我相信其他答案都很好並且有效。 但是我的設定代理解決了開發者自由 。
這個解決方案適用於像我這樣受到谷歌嚴格限制伊朗人的波斯人。
現在我的應用程序gradle看起來像這樣:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "1.6.4"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
這些存儲庫基於OneSignal文檔 。
頂級構建:
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
一切都很好。
Android項目有2個gradle文件:一個存儲在項目范圍內,另一個存儲在應用程序范圍內。 (注意一個項目里面可以有很多應用程序,但通常有一個)。 因此,您只需要在這兩個gradle文件中交換已定義的存儲庫URL。
第1步:在build.gradle
(app)中刪除這些代碼行
repositories {
maven { url 'https://maven.google.com' }
}
第2步:將其添加到build.gradle
(項目)
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
有一件事你必須知道28.0.0
是android.support
的最后一個穩定版本。 因此,您可能希望降級版本或將所有內容遷移到androidX
。
28.0.0的穩定版本將是打包為android.support的最終功能版本。 所有后續功能版本僅作為androidx打包的工件提供。
看看這個鏈接 ,歡迎來到androidX
的新時代。
請嘗試以下方法:
1)從構建工具中取消選中離線工作:文件 - >其他設置 - >默認設置 - >構建,執行,部署 - >構建工具 - > Gradle->取消選中離線工作選項。
2)如果上面不起作用,那么轉到項目的構建gradle並在存儲庫下添加以下內容:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
將此部分從模塊的build.gradle
合並到根項目的build.gradle
:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
repositories {
maven { url 'https://maven.google.com' }
}
只保留模塊的build.gradle
中的這些行:
apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
android {
...
}
根項目的build.gradle
應該看起來像這樣:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
您仍然可以使用版本28.0.0,但似乎是時候遷移到Android X了 !
根據支持庫文檔 :
注意:隨着Android 9.0(API級別28)的發布,有一個名為AndroidX的支持庫的新版本,它是Jetpack的一部分。 AndroidX庫包含現有的支持庫,還包括最新的Jetpack組件。
您可以繼續使用支持庫。 歷史工件(那些版本為27及更早版本,打包為android.support。*)將繼續在Google Maven上提供。 但是,所有新的庫開發都將在AndroidX庫中進行。
我們建議在所有新項目中使用AndroidX庫。 您還應該考慮將現有項目遷移到AndroidX。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.