【问题标题】:Android gradle trouble after updating Android Studio更新Android Studio后的Android gradle问题
【发布时间】:2016-01-25 03:37:53
【问题描述】:

我曾经有一个旧版本的 Android Studio(不完全确定是哪一个,它是几个月前 / 可能是去年的),一切都运行良好。它是某种 RC 版本,也许是 RC-2?

不管怎样,上周我更新到最新版本 v1.4,现在 gradle 和其他一切都完全坏了。代码未更改。

这是我的旧 gradle 文件:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0-rc2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

这个文件给出了错误"You must use a newer version of the Android Gradle plugin. The minimum supported version is 1.0.0 and the recommended version is 1.3.0".

因此,当我将 gradle 更改为 1.3.0(或 1.0.0)时,该错误消失了,但被替换为 101 个错误,所有这些错误如下所示:

错误:(2) 检索项目的父项时出错:找不到资源 匹配给定名称“android:Widget.Material.Spinner.Underlined”。

例如,上述错误引用了一个名为 ldltr-v21/values-ldltr-v21.xml 的 Android 文件,而该文件根本不在我的项目中。这是一个包含内容的标准 Android 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- From: file:/usr/local/google/buildbot/repo_clients/https___googleplex-android.googlesource.com_a_platform_manifest.git/mnc-supportlib-release/frameworks/support/v7/appcompat/res/values-ldltr-v21/styles_base.xml -->
    <eat-comment/>
    <style name="Base.Widget.AppCompat.Spinner.Underlined" parent="android:Widget.Material.Spinner.Underlined"/>
</resources>

再次。我的代码都没有改变,突然一切都被打破了。我还尝试过清理/构建、使缓存无效和重新启动,以及恢复到我最新的提交/重建。没有任何效果;我怎样才能解决这个问题?

【问题讨论】:

  • 检查你的compileSdkVersion 21

标签: android android-studio gradle android-gradle-plugin android-sdk-tools


【解决方案1】:

更新您的 build.gradle 文件。

使用最后一个稳定的插件:1.3.1

classpath 'com.android.tools.build:gradle:1.3.1'

更新您的 gradle 版本,更改 gradle/wrapper/gradle-wrapper.properties 文件

distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

然后检查你的依赖:

AppCompat 构建的主题需要具有相同级别的 API 来编译您的应用程序。

意思是

  //You have to use compileSdkVersion=23
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'com.android.support:appcompat-v7:23.0.0'


  //it requires compileSdkVersion 22
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.android.support:appcompat-v7:22.2.0'
  compile 'com.android.support:appcompat-v7:22.1.1'
  compile 'com.android.support:appcompat-v7:22.1.0'
  compile 'com.android.support:appcompat-v7:22.0.0'

  //it requires compileSdkVersion 21
  compile 'com.android.support:appcompat-v7:21.0.3'
  compile 'com.android.support:appcompat-v7:21.0.2'
  compile 'com.android.support:appcompat-v7:21.0.0'

【讨论】:

  • 我的目标是 SDK 19,现在我收到一个新错误:下午 6:51:35 运行构建时出错:目标模块未定义这些相关吗?
  • 另外,现在重启后(我以前做过很多次)Android Studio 警告我这个项目没有使用 Gradle.... 什么!!哈哈,我不知道到底发生了什么
猜你喜欢
  • 2014-07-29
  • 1970-01-01
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多