【发布时间】:2019-06-10 12:52:10
【问题描述】:
我知道这些问题:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project
我已经阅读了这些文档:
Migrate to Android Plugin for Gradle 3.0.0
所以我发布了这个问题,相信它不是重复的。
我已经安装了 Android Studio 3.4.1。我之前没有任何以前的版本,我开始了一个新项目。
Gradle 文件中的每个设置都是由 Android Studio 自己设置的,我已经全部检查过了。
我已经试过了
- 使 android studio 失效并重启
- Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project
- Failed to resolve: com.android.support:cardview-v7:26.0.0 android
这些是文件内容:
build.gradle(模块:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
顶级 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.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/'}
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/guardian/android' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
#Mon Jun 10 17:40:01 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
我在存储库中使用google(),因为here 明确表示:
// If you're using a version of Gradle lower than 4.1, you must instead use: // maven { // url 'https://maven.google.com' // }
我的 gradle 版本是 4.1,所以我不需要上面的代码。
但正如其他人一直在询问的那样,我仍然收到此错误:
无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.constraintlayout:constraintlayout:1.1.3.
错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.versionedparcelable:versionedparcelable:1.0.0.
错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.lifecycle:lifecycle-runtime:2.0.0.
错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.legacy:legacy-support-core-ui:1.0.0.
错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.vectordrawable:vectordrawable-animated:1.0.0.
错误:无法解决依赖关系 ':app@releaseUnitTest/compileClasspath': 无法解析 androidx.fragment:fragment:1.0.0.
我还取消了 gradle 中的离线复选框并使用默认值
当我在AS 3.4.1 中创建一个新项目并且已经设置了所有必要的设置时,为什么会出现此错误?
【问题讨论】:
-
如果您打算使用AndroidX,您是否尝试过这些步骤。 stackoverflow.com/a/54825603/1318946
-
是的,我做到了。它说没有找到用法。 @PratikButaniAndroidDev