I'm new to Gradle and I need to make sure that my Android project has the latest dependencies with regards to RxAndroid and RxJava. Forgive me for my ignorance but could someone explain how I go about to make sure that the libraries I include in my project are the latest ones? Where does Gradle downloads these libraries from? Is there a central repository? Is GitHub the source? It's not clear from the code shown below:
build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
}
I would really appreciate if someone could shed some light with regards to this topic.
Gradle downloads them from Maven or other repos. I don't believe GitHub hosts the libraries themselves, but the link to download the libraries could be found on GitHub.
To ensure they are the latest version, you will have to go the library's web page(Git hub page usually) and check if a latest version has been released.
If I am not wrong, you could add a + sign at the end and when you sync Gradle with work in offline mode turned off, it should fetch the latest version of the library.
Eg:
compile 'com.android.support:appcompat-v7:23.3.0+'
compile 'io.reactivex:rxandroid:1.0.1+'
The above line will ensure that 1.0.1 is the min version that you will download and if there are any higher version, it will download that instead.
WARNING : this is not a safe thing to do, because the latest version of library will be automatically downloaded and the changes in the newer version of the library might have breaking changes, and break your app. For instance the methods you use from a library might be removed in the new library or even worse things could happen and it has to me. I suggest you set some time apart once every few weeks and see if there are new updates and consider if it is safe to update.
Deciding to add a library to your project must be carefully thought through, as you are making the project dependent on it and if that library dies out or is buggy, your project too will be screwed. Incase you didn't, I suggest you read this on how being careless with adding dependencies literally broke the internet.
You can just add a plus to the end of each, although it's not recommended as sometimes new libs will break your code.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0+'
compile 'io.reactivex:rxandroid:1.0.1+'
compile 'io.reactivex:rxjava:1.0.14+'
}
Here are the latest:
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'io.reactivex:rxandroid:1.2.0' // Upgraded
compile 'io.reactivex:rxjava:1.1.5' // Upgraded
testCompile 'junit:junit:4.12'
}
check here
Related
I'm trying to migrate an Android project developed with Eclipse ADT to Android Studio. I've already read the instructions mentioned here http://developer.android.com/sdk/installing/migrate.html and it works fine!
Gradle builds a new android project but I need to "hardcode"(modify manually) the gradle.build file in order to make the libraries work properly. All the other stuffs work fine.
This is the ADT project
MyApplication/
-->assets/
-->libs/
---->android-support-v7-appcompat.jar
---->android-support-design.jar
-->res/
-->src/
-->AndroidManifest.xml
-->project.properties
The first library is automatically recognized by Gradle, and it is substituted with
compile 'com.android.support:appcompat-v7:23.2.1'
in the grandle.build file.
Instead the "android-support-design.jar" is not recognized and it is added to the gradle.build as
compile file('libs/android-support-design.jar')
but it is not working at all.
At the moment, I need to manually substitute the
compile file('libs/android-support-design.jar')
with
compile 'com.android.support:design:23.2.1'
In order to make the build work effectively.
Is there any way to force Gradle to recognize that library and automatically import it? Can I download a version of that library that is recognized, anywhere? At the moment I'm taking both libraries from
<sdk>/extras/android/support/
Thank you all.
I need to "hardcode" the gradle.build file in order to make the libraries work properly
I'm not sure what you mean by "recognize" and "hardcode", but if you just have jar files that you can't use the compile line like for the support libraries, then you can use this line, which will take any jar file in the libs/ folder and compile it. You don't need to hard-code any of those.
compile fileTree(dir: 'libs', include: ['*.jar'])
Otherwise, you should already have these.
compile "com.android.support:appcompat-v7:23.2.1"
compile "com.android.support:design:23.2.1"
But, if you want to get fancy with Gradle, you can do something like this to keep all the support libraries the same version.
ext {
supportLibVersion = '23.2.1' // variable that can be referenced to keep support libs consistent
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
In Gradle in Android Studio I noticed providing a dependency scope is optional. For example:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
'org.hamcrest:hamcrest-core:1.3'
'org.hamcrest:hamcrest-library:1.3'
}
Notice the very last two libraries don't have a compile scope attached. I left it blank and I was still able to sync gradle. What is the default scope if nothing is specified here ?
The scope is actually a label for a given dependency configuration. It depends very much on the gradle plugins you are using (i.e.: java plugin or android plugin).
If you don't add any configuration label, it will be saved as an unlabeled dependency.
Most of the time if you need a implementation dependency and do not add the label, your build will break. If it doesn't break it could be because:
You were not actually needing the dependency
You are using a gradle plugin that handles nicely unlabeled dependencies
Or (more probably), the dependency is already on your build cache or partial build and therefore the compiler is still able to find the classes, but will break if you clean the project.
Related documentation on dependency configuration for gradle
There is a small update to Logain's answer. compile is deprecated now. implementation can be used to replace it.
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
I'm unable to get the YouTubePlayerSupportFragment correctly compiled into my project. I've reviewed this post and this post and have implemented the suggestions there, but still no luck.
Here is what I have tried so far: I have the YouTube API saved in my libs folder. The dependencies section of my gradle file looks like this. You can see that I've tried to include the library using gradle. Whether I comment this line out or not (and sync, of course), I still have the same result.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.google.dagger:dagger:2.0.1'
apt 'com.google.dagger:dagger-compiler:2.0.1'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'commons-codec:commons-codec:1.10'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'joda-time:joda-time:2.8.2'
compile 'com.google.android.gms:play-services:7.8.0'
// compile 'com.google.apis:google-api-services-youtube:v3-rev149-1.20.0'
}
Here is a screenshot to show how I have the YouTube API saved in the libs folder.
I followed the instructions from the Google Developers guide to download the zip file and understand which jars needed to be copied over. These instructions include the following:
Dependencies for all Platforms
The following are the jars from the libs folder required for
applications on all platforms: google-api-client-1.20.0.jar
google-oauth-client-1.20.0.jar google-http-client-1.20.0.jar
jsr305-1.3.9.jar google-http-client-gson-1.20.0.jar (when using GSON)
gson-2.1.jar google-http-client-jackson2-1.20.0.jar (when using
Jackson 2) jackson-core-$2.1.3.jar google-http-client-jdo-1.20.0.jar
(when using JDO) jdo2-api-2.3-eb.jar Android Dependencies
The following are the jars from the libs folder required for android
applications or a newer compatible version of each dependency:
google-api-client-android-1.20.0.jar (for SDK >= 2.1)
google-http-client-android-1.20.0.jar
Finally, I looked at the project structure, and it looks great here:
So why doesn't this thing resolve to a type? I'm completely at a loss. Thanks for any advice.
You have included the wrong YouTube SDK.
YouTubePlayerSupportFragment is part of the YouTube Player API package, that you can find here: https://developers.google.com/youtube/android/player/
Just download the JAR archive, put it in your 'libs' folder, and you'll be good to go.
I am new to Android development. so the external libraries (aka. dependencies) are defined in build.gradle like
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v13:21.0.0'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.google.code.gson:gson:2.1'
compile 'de.greenrobot:eventbus:2.4.0'
}
Is there an easy way to find out if any of these libraries has got a newer version for update? I noticed that Android Studio reminds new version available for gson but not for other libraries.
I'm from the iOS background, CocoaPods is the tool we use to manage external libraries. Using pod outdated command, it is very easy to figure out which libs have new version for upgrade.
There is a lint option called "Newer Library Versions Available".
You may need to add this to your build.gradle as well:
android {
...
lintOptions { warning 'NewerVersionAvailable' }
}
Then you can run Analyze > Run Inspection By Name... > Newer Library Versions Available to get a list of outdated dependencies.
Bintray has a watching mechanism that notifies you when a new version of a package you're watching is updated.
I am with JFrog, the company behind Bintray and [artifactory], see my profile for details and links.
I'm trying to add a Leader Board to a Chrome cast project and am getting errors. Android project in Android Studio. In my gradle build - Error: more than one library with package name 'com.google.android.gms'
I understand why you don't want to use two different libraries with the same name, but not sure how to use the same library throughout the project. Here are the two uses of gms:
1) Main activity has dependency on 'CastCompanionLibrary-android-master' which then uses google-play-services_lib. I'm not sure which version of gms this uses, but the version number is referenced in the manifest. Is this just grabbing the version # of play services that they have installed on their phone?
2) BaseGameUtils - has dependency on com.google.android.gms:play-services:+ (I think this is grabbing the most recent version of play-services, but doesn't match the other one.
MainActivity gradle file
dependencies {
compile project(':BaseGameUtils')
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':CastCompanionLibrary-android-master')
}
CastCompanionLibrary-android-master dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':android-support-v7-appcompat')
compile project(':android-support-v7-mediarouter')
compile project(':google-play-services_lib')
}
BaseGameUtils dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:+'
}
So, the problem (I think) is these two versions of com.google.android.gms, but how do I rectify it so that they all use the same version. I've had almost 2 years of working with Android, but this is my first question on stack overflow. Help is appreciated - Is there a guru out there that has the answer to this?
Seems like you have modified the gradle file for CCL since what you have there does not match with what CCL has in GitHub. The best approach is to only use the piece of play services that you need; for example CCL only needs the play-services-cast (besides the base, which will be pulled in automatically) so if you follow that pattern, things would look smaller (less possibility of running into the 64K dex limit) and less collisions.CCL, in Github, lists its dependency as:
compile 'com.google.android.gms:play-services-cast:6.5+' so you might want to start using versions and also follow the recomendation I just made (same applies for any other code that you have and uses play services; just pull in what you really need)