【问题标题】:Failed to resolve: com.google.android.material:material:1.0.0-alpha1无法解决:com.google.android.material:material:1.0.0-alpha1
【发布时间】:2018-05-05 20:45:49
【问题描述】:

所以我按照官方文档将Material Components库添加到我的项目https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md

但它会引发以下错误 “无法解决:com.google.android.material:material:1.0.0-alpha1”

我已尝试安装 Android Studio 建议的存储库和同步项目,但无济于事。

我的项目配置

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:3.2.1'
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}


task clean(type: Delete) {
delete rootProject.buildDir
}

和应用配置

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "mlluell.eftremp"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-auth:15.1.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.firebase:firebase-database:15.0.1'
implementation 'com.google.firebase:firebase-storage:15.0.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.material:material:1.0.0-alpha1'

//imatges recyclerview
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:3.3.0'

// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:3.3.0'

// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:3.3.0'


testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 这些说明似乎不正确,至少目前是这样。如果您在 Web 浏览器中访问 maven.google.com,则该工件不在列出的 AFAICT 中。我相信这个存储库将在下周的 Google I|O 上更正式地亮相;你可能想推迟尝试使用它,直到那时。
  • 如果您在使用材料库时遇到问题stackoverflow.com/a/53693942/4395804,这是另一个答案

标签: android gradle


【解决方案1】:

代替:

implementation 'com.google.android.material:material:1.1.0'

用途:

   implementation group: 'com.google.android.material', name: 'material', version: '1.1.0-alpha05'

它有效。

【讨论】:

  • 这行得通,谢谢!知道为什么它以一种方式工作而不是另一种吗?
  • @DanishKhan 说实话,我猜如果是 alpha 版本,它无法以标准格式找到它们,我猜这是一个存储库问题。
  • @Lancelot 正确添加了 alpha 和数字之间缺少的 0:´version: '1.1.0-alpha05'´ 当前版本是'com.google.android.material:material:1.2.0-beta01'
【解决方案2】:

既然 I|O 已经开始,我想我会分享为我解决此问题的方法。

我的初始设置与您大致相同。为了让它工作,我必须改变以下内容:

  • 将SdkVersion 编译为'android-P'
  • 支持库到'28.0.0-alpha1'
  • 在依赖项块中包含api 'com.android.support:design:28.0.0-alpha1'
  • SDK 平台更新 - Android P 预览版(最新)
  • targetSdkVersion 'P'

然后我做了仪式性的“使缓存无效/重新启动”并重新构建项目以取得良好的效果。

【讨论】:

  • 你为我节省了大量时间
  • 即使您使用'android-P' 编译,您仍然可以通过设置minSdkVersion 来保持与旧设备的兼容性。您只需要确保处理好几个尚未反向移植的新组件
  • @ImArtVandalay,你是怎么弄明白的?
  • @parekhkruti26:只是反复试验。但后来我确实在 2018 I/O Material Components Developer 教程中遇到了this as confirmation
  • 这是否允许您使用适用于 Android 7/8/9 的组件?
【解决方案3】:

对于 ANDROIDX 用户:

可以如下实现:

AndroidX:

implementation 'com.google.android.material:material:1.0.0'

旧的构建工件用户可以使用以下实现:

implementation 'com.android.support:design:[Enter Design library version here]'

使用不带方括号的版本。 您可以通过此链接找到设计库版本:https://mvnrepository.com/artifact/com.android.support/design/28.0.0

【讨论】:

    【解决方案4】:
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'`
    

    【讨论】:

    • 添加一些可以解释你所做的事情的 cmets。
    【解决方案5】:

    确保您的 gradle.properties 使用以下行启用了 AndroidX:

    android.useAndroidX = true
    

    如果没有添加,则添加此行并再次同步项目

    Visit For More Details

    【讨论】:

      【解决方案6】:

      androidx 用户: 通过使用最新版本更新所有依赖项,我的问题得到了解决。 2分钟就解决了。我以前的版本是 1.0.2 并显示相同的错误。我只是点击了出现在错误下方的“在项目结构对话框中显示”。从那里您将获得将依赖项更新到最新版本的选项。对于 androidx 以外的用户,可能是相同的解决方案。

      【讨论】:

        【解决方案7】:

        嗯,一个小时前发生在我身上... 我总是建议检查最基本的问题,例如:

        转到 >> Gradle module.app:

        implementation 'com.google.android.material:material:1.2.1'
        

        当您遇到语法错误时; Failed to resolve: com.google.android.material:material:x.x.x 出现。

        祝你有美好的一天!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-11-26
          • 1970-01-01
          • 2016-06-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-04-02
          相关资源
          最近更新 更多