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:
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
}
}
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
I experience the same issue last week and resolved it by:
open Android SDK Manager
Scroll the the bottom in the section "Extras"
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.
Have you tried to invalidate the cache and restart the android studio?
We can add appcompat to our project in two ways,
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'])
.....
}
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.
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 RestartSync project with gradle file It was not working for me, I even added support library as jar in libsAs 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.
Related
Here i got a problem, I have already installed build tool in revision 24.0.1, here is the screen snapshot from my terminal:
And in fact I think I wrote it well in the build.gradle filebuildToolsVersion "24.0.1", but while sync the project it still appear such error:
fail to find build tool revision 24.0.1 install such build tools
Another question is about the file place order in android studio. Below is the imported project hierarchy and the manifest file is under the main folder and i can not find any usage file under android perspective.
Such a project hierarchy I have never seen, maybe there is somebody who could demonstrate such answer to me. Thank you.
Update: Here is the build.gradle file picture
You are doing it in the wrong way. There are two types of build.gradle files. The first one is for your project and the second type for module which can be more than one. In your case you are mixing both.
The project's build.gradle should like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the module build.gradle should look something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.something"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
}
Regarding your second question, the hierarchy you see is called Project view.
By default, Android Studio displays your project files in the Android view. This view does not reflect the actual file hierarchy on disk, but is organized by modules and file types to simplify navigation between key source files of your project, hiding certain files or directories that are not commonly used.
(...) To see the actual file structure of the project including all files hidden from the Android view, select Project from the dropdown at the top of the Project window.
Source: https://developer.android.com/studio/projects/index.html
After update with the latest Android support library 23.1 i get this error
Failed to resolve: com.android.support:support-v4:23.0.0
I tried all combination of 23.+ and 23.1.0 and 23.1.+ etc. How to make it run properly?
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "ua.g.tfinder"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.+'
compile 'com.android.support:support-v4:23.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:design:23.0.+'
compile 'com.google.android.gms:play-services:7.5.+'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
The support libraries are now available through Google's Maven repository.
Step 1: Open the build.gradle file of your project.
Step 2: Make sure that the repositories section includes a maven section with the "https://maven.google.com" url in it.
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
I ran into the same problem today. Although the SDK Manager marked a few libraries as installed, investigating the location of the files showed me the correct folder structure, without any files in them.
For example, checking out the location of 23.1.0 appcompat-v7 on my Mac:
.../sdk/extras/android/m2repository/com/android/support/appcompat-v7
turned out to be an empty folder.
I suspect the update I ran minutes before went wrong somehow.
What solved it for me:
in Android Studio, open Appearance and Behaviour -> System Settings -> SDK Manager
under tab "SDK Tools" un-check the libraries causing problems
click "apply" to uninstall them
re-check the same libraries
click "apply" to reinstall them
close SDK Manager and run Gradle sync / build
Had to add "Android Support Repository" from SDK Manager.
As you already have v7 dependency added in your gradle file no need to add dependency for v4 because it is already included in v7 library.
gradle file should looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "ua.guru.lvivflatfinder"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.google.android.gms:play-services:8.1.0'
}
.......
(build.gradle (MOdule.app)
implementation 'com.android.support:cardview-v7:28.0.0-rc01'
In my case, opening SDK manager and installing Local Maven Repository for Support Libraries fixed my issue.
Go to File -> Project Structure then select Dependencies tab and remove com.android.support:support-v4:23.0.0
It worked for me
Gradle sync / build
implementation 'com.android.support:cardview-v7:28.0.0-rc01'
ready and go!
I got a similar problem, was trying to change versions and so on. Did not work for me. Only after I changed the version and restarted Studio it started to work. Probably gradle doesn't sync that normaly while you don't restart Studio.
I got this error when I tried to build the app while being OFFLINE. After connecting to the internet it worked :-)
he support libraries are now available through Google's Maven repository.
Step 1: Open the build.gradle file of your project and add the following dependencies.
allprojects {
repositories {
jcenter()
mavenLocal()
mavenCentral()
jcenter()
google()
}
I'm trying to set up Double Espresso, but that's probably not relevant here. What I'm trying to do is to set up a project in Android Studio using Gradle.
I'm very new to Gradle and build tools in general, though I've successfully used Maven before. Despite an hour of searching I can't find an answer to a very simple question.
In Jake Wharton's instructions it says
No more fumbling with local jars or dependency conflicts. Pull it in with one line:
androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
Pull in where? Where do I put/execute that command to import the project? In the command prompt? Do I put it in one of the scripts?
Thanks for any help.
You have a build.gradle file inside your app folder. In that file you can configure your project, "dependencies" and other options. It's very similar to maven. You have another build.gradle file in your root folder from your project. This conf file is more general and call the other build.gradle file.
e.g I have in one of my projects
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.acostela.example"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.+'
compile "com.android.support:gridlayout-v7:18.0.+"
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'commons-net:commons-net:3.3'
compile 'net.sf.opencsv:opencsv:2.3'
}
Dependencies here are similar to maven and the use in that tool of "/".
Gradle take libs from repositories in the same way of maven. In fact you can use the maven repository. You have a tab with the gradle sentence to download libraries.
http://mvnrepository.com/artifact/com.squareup.assertj/assertj-android/1.0.0
Trying to use MultiDexApplication in my app, but the class is not recognized when I try to extend my application activity with it.
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
defaultConfig {
applicationId 'com.myapp'
minSdkVersion 10
targetSdkVersion 21
versionCode 115
versionName '4.8'
}
buildTypes {
debug {
debuggable true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
debuggable false
runProguard true
zipAlign true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile project(':facebook')
}
You can see that I'm compiling on 21, using the latest build tools, and the latest google play services and support library.
Has anyone gotten this to work?
MultiDexApplication class is not part of appcompat-v7 library. It is being shipped in a separate jar (called android-support-multidex).
Find the android-support-multidex.jar under /sdk/extras/android/support/multidex/library/libs (available from revision 21 of support library) and copy it to your project's libs folder.
Update (11/5/2014):
The jar is now available in central repository:
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
For more info, see here.
Update (27/9/2021):
Jetpack (AndroidX) users should add this as a dependency:
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
Although this question is quite old, I got this error in a multi-module setup when trying to build the different modules together as one APK for API < 21. I already refactored to AndroidX, but the multidex docs don't mention AndroidX yet.
If you are using AndroidX, make sure to replace the old multidex dependency
compile 'com.android.support:multidex:1.0.3'
with the new one
implementation 'androidx.multidex:multidex:2.0.0'
I have followed THIS blog post according to which MultiDexApplication should be included in r21 of support library.
My IDE had trouble resolving it also.
I made it work for now with the help of MULTIDEX github project by adding (you can see more details on the project's page):
android {
dexOptions {
preDexLibraries = false
}
}
repositories {
jcenter()
}
dependencies {
compile 'com.google.android:multidex:0.1'
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex' // enable multidex
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}
}
and adding $project_dir/multidex.keep file with following contents:
android/support/multidex/BuildConfig.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDexExtractor$1.class
android/support/multidex/MultiDexExtractor.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/ZipUtil.class
The github project page mentions also some consideration for the contents of your implementation of MultiDexApplication class:
The static fields in your application class will be loaded before the
MultiDex#installbe called! So the suggestion is to avoid static fields
with types that can be placed out of main classes.dex file.
The methods of your application class may not have access to other classes
that are loaded after your application class. As workarround for this,
you can create another class (any class, in the example above, I use
Runnable) and execute the method content inside it.
I got the solution :)
Upgrade to jdk 8 and change JDK location in Android Studio in
File > Project Structure > SDK Location
Find and change JDK location and click OK
I've imported Eclipse Android project to Android Studio and it fails to compile with following errors:
Error:(7, 8) error: duplicate class: com.company.fragment.PrimaryFragment$$ViewInjector
I've tried adding apt plugin:
apply plugin: 'android'
apply plugin: 'apt'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
disable 'InvalidPackage'
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
compile project(':library')
compile 'com.android.support:support-v4:+'
apt "com.jakewharton:butterknife:5.1.1"
compile 'com.jakewharton:butterknife:5.1.1'
}
I think that this has something to do with Butterknife. But when I make a clean project with it, everything is ok.
If you still have the target/build folders from eclipse in your build directory it might be a good idea to delete those.
Also Cleaning project under Project -> Clean might help.
Also if you are running maven or gradle from command line, it would be wise to run:
maven clean
or
gradle clean
You don't need both the apt and the compile dependency, only the compile dependency.
By having it twice, the annotation processor is running twice (with two different output directories) which means the generated classes are created twice. The error you are seeing is because there are two identical classes being generated for your PrimaryFragment.
The apt scope (and plugin) are only needed for libraries which separate their runtimes from their annotation processors (sometimes called compilers). An example of this would be Dagger which has a dagger and dagger-compiler.