为 api 26 (Android) 设置 Gradle [英] Setting up Gradle for api 26 (Android)

查看:32
本文介绍了为 api 26 (Android) 设置 Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我将 Nexus 5x 升级到 Android O DP3 后,我无法测试我的应用程序.我收到错误,因为我没有配置我的 Gradle 文件以使用新的 API 级别 (26).

Since I have upgraded my Nexus 5x to Android O DP3 I am not able to test my applications. I get the error for not having configured my Gradle-file to work with the new API-level (26).

所以我改变了这个和依赖项,但我一直在我所有的支持库上出错

So I changed this and the dependencies, but I keep getting errors on ALL my support libraries like

Failed to resolve: com.android.support:design:26.0.0-beta2

点击

Install repository and sync project

弹出一个下载正确依赖项的进度对话框,但没有消除错误.清理项目、安装存储库然后重建项目也不起作用.

Pops up a progressdialog for downloading the right dependency but does not remove the error. Cleaning up project, installing repositories and then rebuilding the project won't work either.

在 appcompat-v7:26.0.0-beta2 上,我(甚至在 Gradle 同步之前)迅速出现错误:

On appcompat-v7:26.0.0-beta2 I get (before even a Gradle sync) squickly lines with the error:

When using a compileSdkVersion older than android-O revision 2,
the support library version must be 26.0.0-alpha1 or lower (was 26.0.0-beta2)

有人可以帮助我为 Android API 26 正确配置 gradle 文件吗?任何帮助将不胜感激.

Can someone help me get the gradle file to be configured correctly for Android API 26? Any help would be appreciated.

PS:我目前使用的是 Gradle 3.0.0-alpha3,但在 Gradle 2.3.2 上遇到同样的错误

PS: I'm using Gradle 3.0.0-alpha3 at the moment but get the same error on Gradle 2.3.2

我的 Gradle 文件:

My Gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'

defaultConfig {
    applicationId "********"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 3
    versionName "2.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.0.0-beta2'
compile 'com.android.support:design:26.0.0-beta2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:26.0.0-beta2'
compile 'com.android.support:recyclerview-v7:26.0.0-beta2'
compile 'com.redbooth:WelcomeCoordinator:1.0.1'
compile 'com.github.kittinunf.fuel:fuel-android:1.4.0'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.ramotion.foldingcell:folding-cell:1.1.0'
}

推荐答案

您是否添加了 google maven 端点?

重要提示:支持库现在可通过 Google 的 Maven 存储库获得.您无需从 SDK 管理器下载支持存储库.有关详细信息,请参阅支持库设置.

Important: The support libraries are now available through Google's Maven repository. You do not need to download the support repository from the SDK Manager. For more information, see Support Library Setup.

将端点添加到您的 build.gradle 文件:

Add the endpoint to your build.gradle file:

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

从 Android Gradle v3 开始,可以用快捷方式 google() 替换:

Which can be replaced by the shortcut google() since Android Gradle v3:

allprojects {
    repositories {
        jcenter()
        google()
    }
}

如果您在 repositories 中已经有任何 Maven url,您可以在它们之后添加引用,即:

If you already have any maven url inside repositories, you can add the reference after them, i.e.:

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://maven.google.com'
        }
    }
}

这篇关于为 api 26 (Android) 设置 Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆