在OSX上的Android Studio旧版和新版上,Gradle构建失败

当我在我的PC上工作时,我有一个成功的构建项目,并且我已经提交并将其推送到我的Git仓库,然后再迁移到OSX.

现在,我在OSX上安装了Android studio最新版本并尝试构建同一个项目,它在构建资源时出错.在Manifest中构建资源时,会出现多个错误

No resource found that matches the given name

对于drawables和字符串.

通过网络浏览,我想可能更新版本的gradle有一些问题.因此,我将AS的安装降级为AS 1.0并使用了旧的gradle 2.2.不幸的是,这个版本的gradle也会出现同样的错误.

我的build.gradle如下所示:

apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "xxx"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 4
    versionName "1.3"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets {

    main {
        res.srcDirs = [
                "/src/main/res"
        ]
    }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/thermodosdk-1.0.18.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:support-v4:21.0.3'

顶级的build.gradle具有以下类路径:

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
}

堆栈跟踪:

Information:Gradle tasks [:app:generateDebugSources,     :app:generateDebugTestSources]
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices6587Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources
/Users/vidhigoel/AndroidStudioProjects/OMGAndroid/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
Error:(24, 23) No resource found that matches the given name (at 'icon' with value '@drawable/omg_app_icon').
Error:(25, 24) No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(27, 24) No resource found that matches the given name (at 'theme' with value '@style/AppTheme').
Error:(30, 28) No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(86, 28) No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(105, 28) No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(123, 28) No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(137, 28) No resource found that matches the given name (at 'label' with value '@string/title_activity_register_user').
...
Information:BUILD FAILED
Information:Total time: 4.462 secs
Information:17 errors
Information:0 warnings
Information:See complete output in console

请帮我解决这个问题.

最佳答案
你在build.gradle中真的不需要这个部分:

sourceSets {

    main {
        res.srcDirs = [
                "/src/main/res"
        ]
    }
}

>这是默认值,您无需将其放在那里.
>你的路径错了.正如我所说它是默认路径而不是真正需要,但如果您仍想添加它check this post on SO以查看如何正确添加它.

你可能只想说:

res.srcDirs = ['res']

从build.gradle中删除sourceSets部分.删除上述配置后,请执行清理和重建.为了更安全的一面也做一个文件 – >使缓存无效并重新启动

转载注明原文:在OSX上的Android Studio旧版和新版上,Gradle构建失败 - 代码日志