简体   繁体   English

Android设计支持库-版本号和Gradle错误

[英]Android design support library - version number and gradle error

I am trying to implement the CoordinatorLayout and Snackbar into my first app. 我正在尝试在我的第一个应用程序中实现CoordinatorLayout和Snackbar。 I know that I need to add an Android design support library as a dependency in the build.gradle file but I am getting the following error in Android Studio 2.3.1: 我知道我需要在build.gradle文件中添加一个Android设计支持库作为依赖项,但是在Android Studio 2.3.1中遇到以下错误:

Failed to resolve: com.android.support.design:25.3.1 无法解决:com.android.support.design:25.3.1

Install Repository and sync project 安装存储库并同步项目

Open File 打开文件

I think there are 2 possible problems: 我认为可能有2个问题:

  1. I have specified the wrong version number - If 25.3.1 is not correct, what is the version number that I should be using? 我指定了错误的版本号-如果25.3.1不正确,我应该使用什么版本号? It's not the same as the appcompat version? 与appcompat版本不同吗? I have searched the web but can't seem to find the answer anywhere. 我已经在网上搜索了,但似乎找不到任何答案。 I have tried older version numbers like 24.0.0 and 22.2.0 but it doesn't work. 我已经尝试使用较旧的版本号,例如24.0.0和22.2.0,但是它不起作用。 I have Android Support Repository version 47.0.0 installed. 我安装了Android支持存储库版本47.0.0。
  2. I haven't actually installed the Android design support library, because the error is telling me to install the repository? 我实际上尚未安装Android设计支持库,因为错误告诉我要安装存储库? I read somewhere on SO that I just need to have the Android Support Repository installed - I do and it appears to be up to date? 我在SO上的某个地方读到我只需要安装Android支持存储库-我知道,它似乎是最新的吗?

Here are the dependencies in my build.gradle file: 这是我的build.gradle文件中的依赖项:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support.design:25.3.1'
testCompile 'junit:junit:4.12'
}

And in the activity_main.xml layout file: 并在activity_main.xml布局文件中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ...
</android.support.design.widget.CoordinatorLayout>

I have found similar questions on SO with gradle build errors but the response is often something along the lines of the advice below which I don't understand, particularly step 3. 我在SO上发现了类似的问题,并且存在gradle构建错误,但是响应通常是以下我不理解的建议,尤其是第3步。

  1. File -> Invalidate caches / Restart 文件->使缓存无效/重新启动

  2. Shutdown Android Studio 关闭Android Studio

  3. Rename/remove .gradle folder in the user home directory 重命名/删除用户主目录中的.gradle文件夹

  4. Restart Android Studio let it download all the Gradle stuff it needs 重新启动Android Studio,让其下载所需的所有Gradle内容

  5. Gradle build success ! Gradle建立成功!

  6. Rebuild project.... success ! 重建项目。...成功!

I would try this except I don't know where to find the .gradle folder? 除了不知道在哪里找到.gradle文件夹外,我将尝试这样做。

You have the following line: 您有以下几行:

compile 'com.android.support.design:25.3.1'

It should be: 它应该是:

compile 'com.android.support:design:25.3.1'

Notice the ':' instead of '.' 注意“:”而不是“。” between 'support' and 'design'. 在“支持”和“设计”之间。

25.3.1 is the correct version at the moment. 25.3.1目前是正确的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加android支持设计库后出现Gradle错误 - Gradle error after add android support design library Android支持设计gradle错误 - Android Support Design gradle error Gradle显示支持库的错误:“模块版本com.android.support:support-v13:19.0.1依赖于库但不是库本身” - Gradle shows error for Support Library: “Module version com.android.support:support-v13:19.0.1 depends on libraries but is not a library itself” Android设计支持和其他库给出了gradle构建错误:“ headerLayout”已经定义 - Android design support and other library give gradle build error: “headerLayout” has already been defined Android Studio Gradle无法找到&#39;com.android.support:design:22.2.0&#39;(Android设计支持库) - Android Studio Gradle cannot find 'com.android.support:design:22.2.0' (the Android Design Support Library) Android支持库Gradle同步错误 - Android Support library Gradle sync error 添加Android支持库时Gradle中的错误 - Error in gradle when adding android support library 添加Android设计支持库后,Gradle构建速度非常慢 - Gradle build is very slow after adding Android Design Support library 库android.support.design.widget错误 - Error with library android.support.design.widget Gradle和Android支持库 - Gradle and Android support library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM