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

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

问题描述

由于我已将Nexus 5x升级到Android O DP3,因此无法测试我的应用程序。我得到了错误,因为没有配置我的Gradle文件来使用新的API级别(26)。

所以我改变了这个和依赖关系,但我保留在所有我的支持库上收到错误,比如

 无法解析:com.android.support:design:26.0.0-beta2 

点击

 安装资源库和同步项目

弹出一个进度对话框,用于下载正确的依赖关系,但不会删除错误。清理项目,安装存储库,然后重建项目也将无法工作。



appcompat-v7



在appcompat-v7:26.0.0-beta2上,我得到了(甚至是Gradle同步之前)的错误:

 当使用比android-O版本2旧的compileSdkVersion,
支持库版本必须是26.0.0-alpha1或更低(是26.0.0-beta2)

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



PS:我现在使用Gradle 3.0.0-alpha3,但在Gradle 2.3.2上得到相同的错误



我的Gradle文件:

  apply plugin:'com.android .application'

android {
compileSdkVersion 26
buildToolsVersion '26 .0.0'

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

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


解决方案

您是否添加了 google maven endpoint


重要提示:支持库现在可通过Google的Maven存储库使用。您无需从SDK Manager下载支持存储库。有关更多信息,请参阅支持库设置


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

  allprojects {
存储库{
jcenter()
maven {
url'https://maven.google.com '
}
}
}

可以取代自从Android Gradle v3以来, google()的快捷方式:

  allprojects {
存储库{
jcenter()
google()
}
}

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

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


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

Clicking on

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

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)

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

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

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'
}

解决方案

Have you added the google maven endpoint?

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.

Add the endpoint to your build.gradle file:

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

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

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

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设置Gradle 26(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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