I just started learning android coding and I keep getting this error:
Add these support library in build.gradle and also make sure the version of the support library(goto sdk manager and get the version number of sdk platform and place it in below dependancy because version of support library and sdk platform should be matched)
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
Try any of the following
Click refresh button on the preview pane
Sync Project with Gradle files
Click Tools > Android > Sync Project with Gradle Files
Rebuild Project
Click Build > Rebuild Project
This seems to come up periodically with Android Studio and it happened again today on an install I haven't used in a while. There may be more than one solution, but as of today June 08, 2016, I made sure two things are set:
1) Make sure you're on SDK/API 23 (or lower if necessary) vs the N preview, and
2) change the theme to "App theme". You may have to choose "Manifest Theme" in the left column before you can see "App Theme" show up as an option in the right column.
3) hit the refresh button (looks like two arrows in a circle)
Referring to a post above, both the support.appCompat and support.design libraries should be automatically added as dependencies to the gradle file, but you can double check them if necessary (and get the newest ones if the versions have changed).
You should see both of these:
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
Why Google and Jet Brains can't keep this from happening I don't know, but as of today, it cleared the problem right away.
Related
In my project I have many libraries defined in dependencies section in gradle. Problem is once in a while (once/twice a day)Android Studio gives me errors like this when opening the project or trying to get a release output:
Error:Unable to resolve dependency for ':TMessagesProj#armv7Debug/compileClasspath': Could not resolve com.google.android.gms:play-services-gcm:11.2.+.
My guess is it is because build tools is trying to check if there is an update for each library and when it doesn't find an Internet connection, it shows this error. If so, how can I change the setting in a way it doesn't have to check for updates? In other words in my project I don't need to update my libraries.
I know there is an offline mode that will probably do the trick! But I don't want to use this feature because it will probably disable some other useful features too. I just want to prevent it from automatically checking for library updates(If that's the problem shown above).
I included some part of my dependencies in gradle here:
dependencies {
compile 'com.google.android.gms:play-services-gcm:11.2.+'
compile 'com.google.android.gms:play-services-maps:11.2.+'
compile 'com.google.android.gms:play-services-vision:11.2.+'
compile 'com.google.android.gms:play-services-wallet:11.2.+'
}
Dependencies with a plus like 11.2.+' will always lead to repeated builds.
You have to specify the full version like:
com.google.android.gms:play-services-gcm:11.2.0
If you do not specify gradle will always be building because its looking for the latest version online of 11.2.+ may be 11.2.4, 11.2.6 etc
When I select Analyze - Infer nullity... in the android studio menu and select any scope (tried even running on a single file) message pops up and says:
The module ... doesn't refer to the existing 'support-annotations'
library with Android nullity annotations. Would you like to add
dependency now?
I click "OK" and then gradle sync starts and progress bar with "infer nullity annotations" title is shown. Then it runs forever like this
I tried adding manually this in gradle:
compile 'com.android.support:support-annotations:23.4.0'
But still have the same result.
I had the exact same issue, but I managed to solve it by manually adding the newest version of the annotations support library to the project through Android Studio build options (it's found on Build -> Edit Libraries and Dependencies on Mac).
The thing here is that Android Studio will probably give you some kind of a warning if you add a support library whose version number is higher than your target API build, but add it anyway. Not sure why, but that did the trick for me.
I'm migrating from Eclipse over to Android Studio and am looking at the Navigation Drawer example from Google. Right away, I see that I get this warning;
It looks like I need to use the v7 library rather than the v4. I can't figure out how to do this. In Eclipse, I just added a dependency from the build tools, but I see no such option in Android Studio. If I look at the build.gradle file, I can see this:
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
I just downloaded Android Studio yesterday, so I think that I should have this dependency somewhere, but I just don't know how to include it. Can someone tell me how to do this?
From within Android Studio, you can go to File, Project Structure, select your module, and go to the Dependencies tab - you'll see a list of dependencies - you can add new dependencies via the + sign near the bottom of that screen - it will automatically suggest the most popular libraries and all Google libraries including the one you want: appcompat-v7. This controls the build.gradle file and, in your case, adds the line:
compile 'com.android.support:appcompat-v7:21.0.3'
Note that you can also use sites such as Gradle, please to manually figure out what the dependency should be and add it to your build.gradle file yourself if you'd like.
I've always added dependencies like this:
dependencies {
compile 'com.android.support:mediarouter-v7:19.+'
}
but in the recent versions of Android Studio, they recommend not to use the + as it can lead to errors. How to know what's the latest version? I can try every combination of 19.y.x until gradle complains, but what's the real way do check?
edit: sometimes, that page helps me figure it out.
There may be other ways, but here is what i use:
You can find out the latest version using Android Studio by replacing the version number of your library in build.gradle compile line, with just + , and click on Sync Now in upper right corner of the window.
in your case, for example
dependencies {
compile 'com.android.support:mediarouter-v7:+'
}
Android Studio will pop up a hint/bulb, which has options Replace with specific version you can click, which will fill-in the latest version in-place of +. Please see below screeshot:
If this doesn't work the first time, let gradle complete its sync, and retry (replace + with + or any file modification will do, click the sync now again and hint bulb will show up).
For example, for your library, i simply pasted this line compile 'com.android.support:mediarouter-v7:+' under my dependencies and followed the above process, Android Studio filled in with below version
Relying on latest version is indeed a dangerous thing to do. Your build can break without you changing anything, just because some library broke backwards compatibility.
The easiest way to know when new version of a library is out is to subscribe to new version notifications in Bintray.
Just click on the "Watch" button on the package page and you'll get an email every time new version is out. Then you'll be able to update the dependency, test it, and only then commit the build script with the new version.
As already mentioned by some other answers you should not use + in dependencies because it may lead to unpredictable builds, so its always better if you first test your builds once a new update is available.
With android studio 2.2 and above Project Structure will show you the latest dependencies available.
Activate it by going to Android Studio > Settings > Build,
Execution, Deployment > Gradle > Experimental and check the Use
new Project Structure dialog
Then open it by going to File >Project Structure > Messages
Original Answer
I use these two links.
This link gives me the latest buildTools Version
https://developer.android.com/studio/releases/build-tools.html
This link gives me the latest supportLibraryVersion
https://developer.android.com/topic/libraries/support-library/revisions.html
Recently, I have found this.
Go to File -> Project Structure
Select the Module, where you want to add the dependency.
Go to the Dependencies Tab
Click + and Choose Library Dependency
Choose whichever Library you need from the list.
(There is also an option for Search, never tried though.)
That's it.
Done.
Thank You.
Avoid to use + in version declare.
You can try andle to check if dependency out of date, also the build tool version and sdk version.
Simple three step:
1. install:
$ sudo pip install andle
2. set sdk:
$ andle setsdk -p <sdk_path>
3. update depedency:
$ andle update -p <project_path> [--dryrun] [--remote]
--dryrun: only print result in console
--remote: check version in jcenter and mavenCentral
the answer of ashoke is correct if you want the latest version.
But if you just want to replace "+" by the version you are currently using (therefor protection yourself against bug in future update)
eg:
compile 'com.android.support:appcompat-v7:21.0.+'
to
compile 'com.android.support:appcompat-v7:21.0.3'
(but not using 23.0.1)
this is the easiest way, no software needed:
run
$ ./gradlew clean tasks --debug > ~/whatever.txt
then look for "com.android.support:appcompat-v7:21.0."
a few line below you will see
"Using com.android.support:appcompat-v7:21.0.3 from Maven repository"
If it is a dependency that comes from Google's maven repository, the best way these days is to go to https://maven.google.com , where google now lets you browse all their libraries and see all the versions available, including the latest version. It looks like this:
You can even do a search for a specific library, and then expand/collapse it as desired:
referencing the play-services via gradle stopped working for me - boiled it down - even the sample I used as a reference in the first place stopped working:
https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':auth'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':auth:compile'.
> Could not find com.google.android.gms:play-services:3.1.36.
Required by:
gpsdemos:auth:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.577 secs
I fear that just the version increased but that raises 2 questions:
#1) what is the new one?
#2) why is the old version gone?
Check if you also installed the "Google Repository". If not, you also have to install the "Google Repository" in your SDK Manager.
Also be aware that there might be 2 SDK installations - one coming from AndroidStudio and one you might have installed. Better consolidate this to one installation - this is a common pitfall - that you have it installed in one installation but it fails when you build with the other installation.
Just install Google Repository form your sdk manager and than restart Android Studio.
In addition to installing the repository and the SDK packages one should be aware that the version number changes periodically. A simple solution at this point is to replace the specific version number with a plus (+) symbol.
compile 'com.google.android.gms:play-services:+'
Google instructions indicate that one should be sure to upgrade the version numbers, however adding the plus deals with the changes in versioning. Also note that when building in Android Studio a message will appear in the status line when a new version is available.
One can view the available versions of play services by drilling down on the correct repository path:
References
This site also has instructions for Eclipse, and other IDE's.
I've been strugglin with this problem for hours till found this post. Just like #ligi said, some people have two SDK folders (Android Studio, which is bundled and Eclipse). The problem is that it doesn't matter if you downloaded the Google Play Services library on both SDK folders, your ANDROID_HOME enviroment variable must be pointing to the SDK folder used by the Android Studio.
SDK Folder A (Used on Eclipse)
SDK Folder B (Used on AS)
ANDROID_HOME=<path to SDK Folder B>
After change the path of this variable the error was gone.
I had the same problem because I had:
compile 'com.google.android.gms:play-services:5.2.8'
and I solved changing the version numbers for a '+'. so the lines has to be:
compile 'com.google.android.gms:play-services:+'
Adding this as a second reference because I had a similar problem..
I had to explicitly add '.aar' as a registered file type under the 'Archives' category in AS settings.
If you already have Google Repository installed, make sure it's updated. I had to update my Google Repository and services. This was after I updated Android Studio.
I added a new environment variable ANDROID_HOME and pointed it to the SDK (C:\Program Files (x86)\Android\android-studio\sdk) that is inside the installation directory of Android Studio. (Environment variables are a part of windows; you access them through the advanced computer properties...google it for more info)
I have the same question.
You should add some dependencies in build.gradle, just looks like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
compile 'com.google.firebase:firebase-ads:11.6.0'
// the key point line
compile 'com.google.android.gms:play-services-auth:11.6.0'
}
I too had the same problem and resolved.
As per the above-mentioned solutions by others, I tried all the things and it does not solve my problem.
Even if you have two SDK locations, no need to worry about it and check whether your android home is set to Android studio SDK (If you have the Android repository and everything in that SDK location).
Solution:
Go to Your project structure
Select your modules
Click the dependance tap on the right side
Add library dependency
"com.google.android.gms:play-service:+"
I hope it will solve your problem.
By mistake I added the compile com.google.android.gms:play-services:5.+ in dependencies in build script block. You should add it in the second dependency block. make changes->synch project with gradle.
Personally this post helped me to solve this issue by moving the google() to the top of the repositories.