9

I inherited a project which uses appcompat-v7:20.0.0
I'm not able to build the project, because it seems that gradle doesn't include the appcompat library while synching/building.

My dependencies in the build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.google.android.gms:play-services:+'
}

Also no play services are pulled into the project, but nine old androids is(I tried including different libraries, it seemed that everything from jcenter is downloaded) As you can see in the following screenshot:

external libraries

The gradle plugin is 1.0.0 and there are no problems during synching.
Are there any known solutions to such type of problem?

EDIT 1:
Android Support Repository
Android Support Library
Google Play Services
Are all installed. However it also works for newly created projects.

EDIT 2:

The ./gradlew build output:

Caused by: org.gradle.internal.UncheckedException: com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/stephan/Library/Android/sdk/build-tools/20.0.0/aapt package -f --no-crunch -I /Users/stephan/Library/Android/sdk/platforms/android-21/android.jar -M /Users/project-path/build/intermediates/manifests/full/flavor/beta/AndroidManifest.xml -S /Users/project-path/build/intermediates/res/flavor/beta -A /Users/project-path/build/intermediates/assets/flavor/beta -m -J /Users/project-path/build/generated/source/r/flavor/beta -F /Users/project-path/build/intermediates/res/resources-flavor-beta.ap_ --debug-mode --custom-package de.my.project -0 apk --output-text-symbols /Users/project-path/build/intermediates/symbols/flavor/beta
Error Code:
1
Output:
/Users/project-path/build/intermediates/res/flavor/beta/values/values.xml:2127: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Light.Base.Spinner'.
/Users/project-path/build/intermediates/res/flavor/beta/values-v16/values.xml:89: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Light.Base.Spinner'.

I also checked Widget.AppCompat.Light.Base.Spinner is part of the values.xml in appcompat-v7 20.0.0
Here are the sdk versions:

compileSdkVersion "Google Inc.:Google APIs:21"
buildToolsVersion "20.0.0"

defaultConfig {
    minSdkVersion 10
    targetSdkVersion 17
}



EDIT 3:

Project root build.gradle

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

allprojects {
    repositories {
        jcenter()
    }
}


App build.gradle

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.google.android.gms:play-services:+'

}

android {
    compileSdkVersion "Google Inc.:Google APIs:21"
    buildToolsVersion "20.0.0"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 17
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }

    signingConfigs {
        conf1 {
            storeFile file("path")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }

        debug {
            storeFile file("path")
            storePassword ""
            keyAlias ""
            keyPassword ""
        }
    }

    buildTypes {
        debug {
            zipAlignEnabled true
            minifyEnabled false
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-project.txt'
            signingConfig signingConfigs.debug
        }

        release {
            zipAlignEnabled true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
            proguardFiles 'proguard-rules.pro'
        }

        beta {
            initWith debug
            signingConfig signingConfigs.debug
        }
    }

    productFlavors {
        flavor1 {
            applicationId "de.package"
            versionCode 1
            versionName "1.0"
            signingConfig signingConfigs.conf1
        }
    }


    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}
Stephan
  • 15,704
  • 7
  • 48
  • 63
  • 2
    `I'm not able to build the project`. What is the error message or symptom that lets you conclude that `appcompat-v7:20.0.0` is not included? – k3b Jul 29 '15 at 12:03
  • 1
    it doesn't appear as external library(shown in the screenshot) and some styles can not be found. eg.: ```Widget.AppCompat.Light.Base.Spinner``` – Stephan Jul 29 '15 at 12:08
  • 1
    In AndroidStudio: have you Right clicked on "main module->Change Module settings" and added the missing dependencies? – k3b Jul 29 '15 at 12:21
  • 1
    It's there, since it just displays the properties of ```build.gradle```. I also just checked out the repository and tried a build without android studio. It's definitely a gradle issue. – Stephan Jul 29 '15 at 12:28
  • 1
    `tried a build without android studio.` this means that building with `gradlew --gui` fails? – k3b Jul 29 '15 at 13:45
  • yes ```./gradlew clean assembleFlavorDebug``` fails. I'm on a Mac. – Stephan Jul 29 '15 at 13:47
  • Post your build.gradle, there's something of strange right there (for example the support-annotation is included twice) – Mimmo Grottoli Aug 04 '15 at 11:49
  • The shown snippets are basically the build.gradle. There are some flavors only containing signing configs. Removing them doesn't change something. – Stephan Aug 04 '15 at 12:02
  • If you have a traditional Android Studio project, you will have two `build.gradle` files, one in the project root and one in the `app/` module. Post both **in their entirety**. BTW, your `compileSdkVersion` should be `21`, unless you are still using Maps V1, which would be rather surprising. – CommonsWare Aug 04 '15 at 12:18
  • I posted the ```build.gradle``` files. No I'm not using Maps v1(As I wrote, I inherited the project) Also the resource file R is not created. – Stephan Aug 04 '15 at 13:35
  • OK, those look fine, other than the `compileSdkVersion` that I mentioned. When you ran `./gradlew clean assembleFlavorDebug`, did it give you the same error message as you cited for `./gradlew build`? Or did you get a different message, something to the effect of not being able to find those dependencies? You might also try adding `--refresh-dependencies` as part of the `gradlew` commands, to force Gradle to scan for dependencies again. – CommonsWare Aug 04 '15 at 13:39
  • Yes, the error message is always the same and also ```--refresh-dependencies``` doesn't help. – Stephan Aug 04 '15 at 13:54
  • Do you have any jar inside the libs folder? Can you try removing the `compile fileTree(dir: 'libs', include: ['*.jar'])` ? – Mimmo Grottoli Aug 04 '15 at 16:16
  • And yes, use compileSdkVersion 21 – Mimmo Grottoli Aug 04 '15 at 16:17
  • Yes, there is the HockeySDK. Changing sdk versions doesn't help. Also removing this jar doesn't solve the problem. – Stephan Aug 04 '15 at 16:22
  • 1
    You might be encountering a problem with older versions of appcompat, where the `project.properties` file in the appcompat folder has an incorrect value set for its SDK. This is referenced here: [http://stackoverflow.com/a/27243716/1748607](http://stackoverflow.com/a/27243716/1748607). Also, Try using the latest version: `compile 'com.android.support:appcompat-v7:22.2.1'` – aindurti Aug 11 '15 at 00:36

5 Answers5

1

I read the documentation for the Android appcompat library and it says that this library depends of v4 support library so you need include this in your project this is the link :https://developer.android.com/tools/support-library/features.html

You only need to change the dependencies in the build.gradle file and add the following line
compile 'com.android.support:support-v4:22.2.1' You can change the version(22.2.1) and put the version 20.0.0 if you want

  • 1
    It's right that v7 depends on v4, but gradle should do the trick and the doku only says: ```If you are using Ant or Eclipse, make sure you include the v4 Support Library…```. But I tried adding v4 and it didn't help either, unfortunately. – Stephan Aug 06 '15 at 07:05
  • 1
    I have build.gradle file like you and in my project the library appcompat is loaded . This is mi dependencies section: dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.google.code.gson:gson:2.3.1' compile 'com.android.support:support-v4:22.2.1'` compile 'com.android.support:gridlayout-v7:22.2.1' compile 'com.android.support:appcompat-v7:22.2.1' repositories { mavenCentral() } – Kiko Blanco Aug 06 '15 at 07:58
  • 1
    As i wrote, it's an old project which I inherited and I have to use appcompat 20 because it still supports holo. I also created a new project with exactly the same dependencies as in the old project and there it works. So there has to be another odd failure, or bug. – Stephan Aug 06 '15 at 08:06
  • have you seen this post http://stackoverflow.com/questions/26530415/error-in-styles-base-xml-file-android-app-no-resource-found-that-matches-the? Maybe, it is your problem – Kiko Blanco Aug 06 '15 at 08:39
0

I experience the same issue last week and resolved it by:

  1. open Android SDK Manager
  2. Scroll the the bottom in the section "Extras"
  3. Check mark Android Support Repository, Android Support Library, and Google Repository

This will download the missing artifacts/jars for the libraries you're missing as a local maven repository so that gradle can find them.

ripple182
  • 801
  • 1
  • 8
  • 13
  • Everything is installed, I even checked it on my disk. – Stephan Jul 29 '15 at 11:54
  • Are you able to update the gradle version that project uses? I'm assuming the logic in the android gradle plugin was updated at some point between version 1 and the current version (1.2.0) to look for the support libraries locally on the machine. – ripple182 Jul 29 '15 at 12:25
  • can you provide your gradle log output? – ripple182 Jul 29 '15 at 15:31
  • It might be an issue with your compileSdkVersion not aligned with the version of the appcomact you're seeking. This overflow post touches on that issue:http://stackoverflow.com/questions/26431676/appcompat-v721-0-0-no-resource-found-that-matches-the-given-name-attr-andro – ripple182 Jul 30 '15 at 11:47
0

Have you tried to invalidate the cache and restart the android studio?

0

We can add appcompat to our project in two ways,

  1. Adding appcompat-v7 as jar file in lib folder

-First download Android Support Library from SDK manager.(If you already downloaded , u can skip this step).

-Redirect to Local SDK path\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar. Copy this jar file & keep it in libs folder of project.

-You have to build project, now appcompat-v7 jar file is added in your project.

-Make sure you have added this comment in build.gradle (Module:app) file of application. dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) ..... }

  1. Adding appcompat-v7 as library dependency

-File --> Project Structure --> Under Modules --> Select app

-Click Dependencies--> Click plus green color icon at top of right side--> Library dependencies --> Select appcompat-v7 from list.

-Now appcompat-v7 is added as library to your project.

Kindly try it out. If you face any problem, please let me know.

Happy coding.. Thanks.

Jayaprakash
  • 101
  • 5
0

I am working on a legacy project which is migrated from Eclipse to Android Studio and i was facing the same issue. No matter how many times I do
Clean Project
Build > Rebuild
Invalidate and Restart
Sync project with gradle file

It was not working for me, I even added support library as jar in libs
As it turns out in my build.gradle file there was this :

configurations {
    all*.exclude group: 'com.android.support'
}

Why it was added? I don't know.
Removing that fixed my issue. So guys, if doing all that and still your issue is not fixed, look for any exclude keywords in your gradle file.

Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54