crazy_coder
crazy_coder

Reputation: 1049

Gradle build failed on Android Studio old and new versions on OSX

I had a successfully building project when I was working on my PC and I committed and pushed it to my Git repo before migrating to OSX.

Now, I installed Android studio latest version on OSX and tried to build the same project and it gives errors in building resources. While building resources in Manifest, it gives multiple errors that say

No resource found that matches the given name

for drawables and strings.

On looking through web, I thought maybe the newer version of gradle has some issues. So, I downgraded my installation of AS to AS 1.0 and used the old gradle 2.2. Unfortunately, this version of gradle also gives the same error.

My build.gradle looks like below:

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'

The build.gradle at top level has the following classpath:

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

Stacktrace:

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

Please help me fix this problem.

Upvotes: 8

Views: 1731

Answers (4)

Kaloglu
Kaloglu

Reputation: 1761

Did you try "Build/Clean Project"?

Upvotes: 0

pRaNaY
pRaNaY

Reputation: 25312

Just change your gradle classpath.

Replace

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

with

classpath 'com.android.tools.build:gradle:2.0.0-alpha3'

EDIT:

also need to add older version of you AppCompact like below:

  dependencies {
...
 compile 'com.android.support:appcompat-v7:19.+'
...
}

Upvotes: 1

Viral Patel
Viral Patel

Reputation: 33398

You don't really need this part in your build.gradle:

sourceSets {

    main {
        res.srcDirs = [
                "/src/main/res"
        ]
    }
}
  1. It is the default value and you do not need to put it there.
  2. You have the wrong path. As i said it is the default path and not really required, but if you still want to add it check this post on SO to see how to add it correctly.

You might just want to say:

res.srcDirs = ['res']

Remove the sourceSets section from the build.gradle. After removing the above mentioned configuration do a clean and rebuild. To be on a safer side also do a File - > Invalidate Cache and Restart

Upvotes: 1

Vishal Thakkar
Vishal Thakkar

Reputation: 2127

Try this link may be help you Installing Gradle In OSX

Please also check this one Points

Your compile SDK version must match the support library's major version.

Since if you are using version 23 of the support library, you need to compile against version 23 of the Android SDK.

Alternatively you can continue compiling against version 22 of the Android SDK by switching to the latest support library v22.

Upvotes: 0

Related Questions