【问题标题】:android studio build suddenly throws a lot of errorsandroid studio build 突然抛出很多错误
【发布时间】:2015-02-23 17:45:12
【问题描述】:

我已经开发这个 android 几天了,突然应用程序构建有很多错误并且无法运行。下面列出了前几个错误

D:\somepath\someotherpath\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\values-v11\values.xml
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(50, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

下面列出了一些可能导致这些错误的原因

我试图通过使用Intel HAXMGenymotion 来加速模拟器。我可以看到 build.gradle

的依赖项的变化

build.gradle old

apply plugin: 'com.android.application'
android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.nirvanasoftware.donor_app"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.android.support:support-v4:20.0.0'
}

**build.gradle 新建 **

apply plugin: 'com.android.application'
android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.nirvanasoftware.donor_app"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
}

依赖性的变化是否会导致构建错误或其他原因。

【问题讨论】:

  • 我看不出这两个版本有什么区别。为什么你认为 targetSdkVersion 和 compileSdkVersion 被“突然”改变了?
  • 您是否仔细检查了 SDK 管理器并根据您安装的版本验证了这些版本号?
  • @aga 我想我需要睡觉了!我已经改变了这个问题,因为正如你指出的目标和编译版本没有改变。但是依赖有。这是我的第一个 android 项目,所以我不确定很多事情。现在,我正在尝试消除这些错误(大约 100 个)。
  • 请在 build.gradle 中设置:minifyEnabled false 而不是 runProguard false
  • @IntelliJAmiya minifyEnabled false 给我以下错误“错误:(16, 0) 构建脚本错误,找到不支持的 Gradle DSL 方法:'minifyEnabled()'!可能的原因可能是:-您使用的是 Gradle方法不存在的版本(修复 Gradle 设置) - 您没有应用提供该方法的 Gradle 插件(应用 Gradle 插件) - 或者构建脚本中有错误 (Goto source)"

标签: java android android-emulator android-studio


【解决方案1】:

在你使用过 appcompat-v7:21.0.3 和 support-v4:21.0.3 的依赖项中

但是你的 compileSdkVersion 是 20 buildToolsVersion 是 "20.0.0"

据我所知,如果你使用 compileSdkVersion 20 那么你应该使用 buildToolsVersion "20.0.0" 并且支持库的版本也应该是 20 而不是 21。如果你想使用 appcompat-v7:21.0.3' 和 support- v4:21.0.3' 你必须使用 compileSdkVersion 21 和 buildToolsVersion 21.xy (这里 x 和 y 将是根据你在计算机上安装的构建工具的数字)

我不确定您的所有问题都是由此引起的。但是如果你的 gradle 同步出现问题,那么突然之间你就会遇到很多问题。因此,如果您除了 gradle 构建文件之外没有其他错误,那么您的问题应该被删除。

我的建议是,如果您想使用最新的 SDK 和支持库,请从 Android SDK 管理器安装最新的构建工具和 SDK,然后使用

compileSdkVersion 21
buildToolsVersion "21.1.2"   // your latest build tools 

以及像这样的依赖

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
}

希望它能解决您的问题。快乐编码:D

另外:在 gradle-1.0.0 的最新 gradle 版本中,runProguard 是一个已弃用的方法。因此,您必须使用 minifyEnabled 并将您的 gradle 版本更新为 1.0.0,而不是使用它。

【讨论】:

  • 是的,你是对的。我没有 API 21 库,错误可能是因为这个。目前,我的目标是 API 20,因此我已将依赖项改回 appcompat-v7:20.0.0,我很高兴它能正常工作。虽然我仍然不知道是什么改变了 build.gradle 中的依赖关系以使用 API 21!
  • 我知道是什么导致依赖项更改为 appcompat-v7:21.0.3。当我添加一个新的活动时,每次都会出现这个问题。任何想法如何在不针对 API 21 的情况下进行修复
  • 我不太清楚。但也许如果您使用的是 Android Studio,IDE 可能希望您使用最新的 API。可能是导致问题的原因。我从来没有遇到过这个问题。我不知道你怎么能克服这个。但如果您使用的是旧版本的 Android Studio,那么更新 IDE 可能会对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 2021-07-02
  • 2022-01-14
  • 2021-09-10
  • 2023-03-21
  • 2017-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多