How do I find Google Play version? - android

When I am setting up gradle, I have to add something like:
compile 'com.google.android.gms:play-services:6.1+'
I don't like to use the +, so I can always know which version the project is being compiled with and so I can avoid some surprise bugs.
In order to find the Google Play version I have currently downloaded, I usually go to the library XML file which I can find something like: "6171000", which is the version as an integer.
Is it there a simpler way to figure out the version that I need to write on gradle?

cd into your module (eg: app) dir, and run gradle command line ..\gradlew -q dependencies --configuration compile. This will resolve the + , and show you exact version being used for your library. See below.
Or, if you use Android Studio, when you modify/edit the version (eg: simply delete/add + at the end), Android Studio will show a yellow-bulb action with Replace with specific version, click on it to automatically replace the + with exact version available.

Go to this site: http://gradleplease.appspot.com/#play-services
You can also search for any library (Ex. recyclerview). This will help you specify the library's latest version.

Related

How to work with build.gradle file in Android Studio

After I make a change in the build.gradle file, what is my next step? I think there must be more steps I am missing…. compiling?? building ?? I am making these changes in Android Studio.
Not being that familiar with the build.gradle file, I am not sure what to do next. Any help would be most appreciated.
I want the change I made to the build.gradle file to have an effect on being able to install my project onto my Oculus Device. Right now I get the "Requires newer sdk version #29 (current version is #25).
after making a change in build.gradle, you have 2 different options, but they're the same thing :
you can click on the gradle sync button, then gradle will apply the recent changes you made or, as you can see in the blue text underneath, you can also make use of the Sync Now feature which will be displayed after any changes have been made.
Here's an example of the complete warning which is displayed after a change
after this, you can build/deploy your project or make changes in code as you need to, your dependencies have now been updated and will be available, assuming gradle syncs successfully

setting library versions issue

Setting the right versions for Gradle dependencies has always seemed, to me, to be an arcane science. For instance take the following line . . .
implementation 'com.firebaseui:firebase-ui:+'
If I build the project with that line I get version 12.0.1 which should be the latest version. No?
If I place my cursor on the + and hit alt-enter and choose "Replace with specific version" I get version 2.1.0. I recall reading somewhere that I should get the latest version stated specifically instead of, in this case, 2.1.0.
So I guess the most dependable way to find the latest version of a library is to compile with + and look to see what I get.
When there is an update android studio show a warning and a mouse over is enough to show you the latest library.
This works great for all google-android components.
For other third party libraries I usually add a link comment in order to check regularly if there is something new.
Note that in the white theme the warnings are not so clear as in the black theme.

Android Studio : How to find latest version number of google specific libraries?

How to find latest version number of google specific libraries from repositories (jcenter etc..) to include in gradle dependencies in Android Studio.
For non google libraries generally I can make a search in jcenter itself. But not able to search google specific libraries there.
You may take example of following libraries.
com.android.support:appcompat-v7:25.1.0'
com.android.support:recyclerview-v7:23.3.0'
Yes as Tim mentioned in the comment Gradle tells you by highlighting particular dependency as a warning.
Trick to update dependency with latest version:
Let me also share a trick through which you can always include the latest version of the particular dependency.
Replace the version number with only "+" sign.
Sync gradle
Now select + sign and press ALT + ENTER, it will show you drop down menu with an option to select latest version.
If you have added a dependency, you can see them by moving the cursor to that library. It will show you a warning
You can then change to new library and sync your project.
Another way to use the latest libraries in Android Studio.
Right click your project and choose Open Module Settings. Project Structure window will appear. Select 'app' from the left pane and choose the 'Dependencies' tab. Include new library dependency by pressing the + icon. Search your needed library in the window opened up. Latest library dependency will appear in the suggestions and you can add them to your project.
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 as desired:

How to set up Android Studio project from scratch that allows me to use groovy

Groovy's 2.4 release comes with official support for android app development http://docs.codehaus.org/display/GROOVY/Groovy+2.4+release+notes.
Having previously used eclipse for Android development, with no experience at all with Android Studio nor with Gradle, the existing instructions for setting up groovy android projects with Android Studio (e.g. http://docs.groovy-lang.org/docs/next/html/documentation/tools-groovyc.html#section-android, https://github.com/groovy/groovy-android-gradle-plugin, or http://hosain.net/2015/02/07/getting-started-with-android-development-using-groovy-2.4-and-android-studio.html) are too vague, do not work for me, and the difference in version numbers used by them is confusing.
I'd like to see detailed step-by-step instructions that work for Android Studio 1.2.1.1 for Linux, and explain how to decide on the version numbers.
EDIT: In 2019, almost 4 years after the question and this answer, the method described below does not work anymore with the current Android Studio version (3.3.2). I could not find versions of the dependencies that still work, and Gradle complains about not being able to download some dependencies.
The fact that 4 years later there is still no reproducible setup guide by the Groovy maintainers is just one indicator that Groovy for Android has no future. We should have seen discussions on patterns regarding how Groovy's dynamic abilities simplify Android development long ago, but this has not happened. I'm going to try Kotlin next, which seems similar enough to Groovy on first glance, apart from the required type annotations, but most important: one does not have to fight so hard against Android Studio to use it.
The original answer follows, it was for a very specific Android Studio version, extended with guesses how to adapt versions of dependencies in future Android Studio versions. According to the comments, this has worked until Android Studio 3.0.1.
After learning by myself how to do it, this is the step-by-step description that I would have liked to read when I started. I have used information from a number of sources. None of these sources worked for me, and they differed in version numbers and where to insert things into build scripts. These instructions are the result of trying out various combinations and filling in some blanks.
From the welcome screen, select "Start a new Android Studio project".
Fill in the app name and a "company domain".
No changes necessary on this page.
This example uses the Blank Activity.
This example uses the name GroovyActivity for the main android screen. The new project now gets created. When android studio has finished creating the project, it shows two open files like this:
Ignore the "rendering problem" for now. It will be resolve itself later during compilation. Close the two open files by clicking on the crosses of their tabs.
Open this build.gradle (Module: app) file:
Insert the following code before the first line:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
}
}
Let's pause for a while to reflect about the version numbers. The lines
classpath 'com.android.tools.build:gradle:1.1.0'
and
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
contain version numbers. How do you know which version number to insert here? At the time you read these instructions, there might have been new releases and unless you have specific version requirements, you will want to use the latest version of whatever it is that is used here in the gradle script.
How can you learn about the latest available versions? It depends:
Note that the editor has highlighted com.android.tools.build:gradle:1.1.0 with a yellow background color. When you hover the mouse pointer over this text, a tooltip appears:
So it seems that android studio knows about the latest version for this thing and advises you to use it. Heed the advice and update this version number to what your version of android studio indicates.
However, no such tooltip appears for this gradle-groovy-android-plugin thing.
What is happening here, anyway? The way I understand it, these names and version numbers identify names of binary components that are used for your app or for building your app, but neither are they part of android studio, nor are you expected to find and install or compile them yourself. Instead, this build script specifies a repository location where these binary components can hopefully be downloaded from. The function jcenter() seems to return the location of the repository. Currently, this repository is bintray.com.
To learn about the latest version of this gradle groovy android plugin, visit bintray.com with your webbrowser and use its search function. Search for groovy-android-plugin. The beginnig of the result looks like this at the time I write this:
The sheer number of listed results is a bit discouraging. I hope they have some relevance sorting in there. Searching through the first page, I only see 2 relevant matches, and the latest version number is 0.3.6.
Having learned about the latest version numbers (at the time of this writing), the correct start of the gradle script is this code:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
}
}
Back to modifying the gradle script, insert the following code after the "apply plugin: 'com.android.application'" line:
apply plugin: 'groovyx.grooid.groovy-android'
Finally, near the end of the gradle script, insert a line
compile 'org.codehaus.groovy:groovy:2.4.1:grooid'
so that it looks like this:
Again, there is a version number here, you can find the latest version on bintray by searching for *grooid.jar (yes, with the star as first character). The result list spans two pages, on the second page I find that 2.4.3 is the latest version:
After changing the gradle file, gradle needs to be "sync"ed. The gradle will sync if you exit android studio completely and restart it, so this is what I've done at this point. This picture shows the syncing after the restart:
Later I found that this icon in the toolbar
triggers the sync.
After the syncing finishes, change the left pane from the "Android" view to the "Project" view with the pull-down menu:
Now build and execute your project in the emulator at least once. I'm not sure what this changes, but if you do not build and execute your project now, while everything is still java sources only, then your groovy sources will not be found after we change to groovy. You can build and run your project using the run icon in the toolbar or with the keyboard shortcut shift-F10.
After executing your project in the emulator, turn back to the left pane, which still shows the "Project" view. In this view, navigate to the app/src/main directory, which currently contains the subdirectories java and res, and the AndroidManifest.xml file.
You will now create an additional "Java Folder" below main, with the help of the context menu:
Be sure to use the menu item New->Folder->Java Folder, and not New->Directory, which would cause problems later on.
In the next screen,
tick the check box "Change Folder Location" and make sure the name in the entry field is src/main/groovy.
If you still have that gradle script open, you will see that it has been adapted and contains the name of the new directory in a line starting with "sourceSets". For good measure, click on the gradle sync icon to make sure everything is properly synced.
Next you want to achieve that the new groovy folder contains the proper package path for the package name of your app. The only way that I have found to achieve this properly, is to create a new, temporary, java class with the context menu of the groovy folder,
and enter the name of this class fully qualified with the package name:
Make sure the spelling of the package name is correct!
The new package will appear in the groovy folder, and inside it, the temporary java class.
All groovy classes and also all java classes that make in some way use of groovy classes have to live below the src/main/groovy directory instead of the src/main/java directory. We can now drag the Activity class from the java directory tree to the same package below the groovy directory:
The temporary class can now be deleted (with the context menu), and the Activity class can be migrated from .java to .groovy by choosing Refactor->Rename File from the context menu.
The file extension .java is simply replaced with a .groovy extension. In the same way, you can later create new java classes and rename their file to .groovy when you actually want to create groovy classes.
You can now change some code in the activity to verify that you can actually have groovy code in an android app. Suggestion:
Give the "Hello World" text view an id in the res/layout/activity_groovy.xml file, like this:
Then, programmatically change the text shown by this view using groovy's string interpolation:
Build and execute in emulator:

Android Studio gradle-###-bin.zip vs. gradle-###-all.zip

One developer on my team has some setting in Android Studio that replaces the distributionUrl entry in gradle/wrapper/gradle-wrapper.properties to use the gradle-###-all.zip, while my Android Studio changes it back to gradle-###-bin.zip.
Basically, my diff always looks like:
-distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
This is annoying. What setting is it, and how do I change it?
gradle-1.12-all.zip file will have binaries, sources, and documentation.
gradle-1.12-bin.zip will have only binaries(That should be enough as you don't need any samples/docs)
If you want to know about gradle wrapper, please check this
http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
If you and the other developer want a uniform experience, place this code in your build.gradle file
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
This will make ./gradlew wrapper --gradle-version 5.6 automatically append -all instead of -bin
For build.gradle.kts:
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Like #San said, -all will have binaries, sources, and documentation, while -bin will just have the binaries.
From what I've seen Android Studio recommends to use gradle-*-all.zip and even provides a "quick fix" to change that. On the other hand, the command ./gradlew wrapper sets up the wrapper using gradle-*-bin.zip, overwriting the previous setting. Make sure nobody is calling "./gradlew wrapper" automatically.
The difference is that the -bin version contains only the runtime and no sample code and documentation. 1
It actually makes sense to go for the -bin version: it is smaller and you're unlikely to need the -all version unless you're debugging Gradle scripts. For this reason, the lint warning to go for the -all version has been removed. Also, new projects are generated with the -bin version by default.
There is a ticket to let IntelliJ download the sources when you need them (after which there really isn't a reason for the -all version), but it hasn't been implemented yet.

Categories

Resources