How to maintain dependencies located at personal servers with gradle - android

We are using android studio for android development.
We are using lot of java libraries in our android development.To keep jar files at one place we kept them on our server.
So here is the scenario
We are using java1.jar,java2.jar,java3.jar,java4.jar all of then located on remote server in one folder.
So how to gradle build script which will download all the four jars for us and ads references to our android project.
Can anyone please guide?

Sounds like you want a private Maven or Ivy repo.
The two biggest for Maven are Nexus and Artifactory.

Related

Android Studio in an offline isolated environment

I manage an offline, air gapped, dev environment that supports many different types of coding projects. My most frustrating project to maintain is our Android Studio projects.
Our dev environment is isolated with no access to the internet. When I have to bring a new machine up for a user or bring in updates to the Android SDK it usually involves heartburn with getting the building in sync across multiple systems.
Is there well documented processes for building Android apps manually, somehow forcing the Gradle/maven libraries to point to an easily copied and setup place? I'm thinking C make file like build process. When we ran Eclipse it was easy to spin up a new system, just scp someone else's environment. Is there some alternative to mirroring the Google maven environment internally?
Am I over thinking the Android studio build process?
The Gradle build system needs to download your dependencies and store them. after downloading them, as long as there is no change to the dependency gradle will use it's cached version of it on its own.
Now, as long as your dependency tasks remain UP-TO-DATE (the dependency has not changed) you should be fine without a connection.
You could also manually put the jars and aars of your dependencies and use gradle to use them instead -
Just modify the dependencies to compile your libs dir and not get them online (all those compile 'com.google.android.gms:play-services-location:8.3.0' are just url's of sorts pointing to the location of the files) and place the necessary files in libs
Another way of obtaining the files easily would be to run the project once in a connected environment and getting the necessary jars from .gradle/caches/
I have been working in similar conditions. To make development much easier you should setup repository management system. Two popular options are Artifactory and Nexus. In your build tools repository configuration, you should refer to your repository management tool address. With this setup, every computer in the network has to get the source code from version control and good to go.(no extra configuration is required)
In an enviroment with internet connection you can prepare the repository your projects depending and after transfering these files to internal network upload these to your repository management tool.

How to use an Android gradle library in several projects without having to deploy it to a server?

I have a utility library, that I'd like to use in several app projects.
I'd like to be able to work on it without having to deploy to a server every time I change something. I need a way to test it in my app before publishing the changes anywhere.
The way I would normally do this is to install the lib to my local maven repository (by local I mean on my dev machine's hard drive), in order to make it visible to the app projects.
Unfortunately, it seems that gradle install doesn't work on Android projects (see this SO question).
So my question is, what's the recommended way to do this and how do most people do? This seems to me as a fairly common use case!
I describe my current workflow. Maybe it helps you, too.
If I develop a library, which targets a special app, I upload a Snapshot build to my local maven repo (upload works). In my app project I reference the Snapshot build. Each time you build the app project Gradle checks for a new Snapshot release. So you definitely use the most current version of your library.
If the library is finished, I upload a finished (no Snapshot) build with a fixed version to my local repository. Later, if I want to extend the library, I increase the version of the library and add the snapshot suffix again.
I'm pretty happy with this workflow. You may want to take a look at one of my build files. In order to upload a Snapshot build, you only need to add the suffix '-SNAPSHOT' to the version string.
If you are already deploying to the maven local, then you can just add that as a repo source for gradle. At least that's what we did:
repositories {
mavenLocal()
}

When to use Maven for an Android project?

I've been working in JSF projects for a couple years; from the standpoint of managing dependencies, maven was a huge time saver as projects may have up to 50 dependencies, and a large number of them were the same from project to project.
Now I'm developing Android projects, I noticed is unusual having more than 5 dependencies, and they're often vary from project to project; in much cases, I don't have a jar to import, but a Project library. So I'm managing my android projects dependencies manually, and didn't miss maven so far.
My questions are:
Is it always a good practice to use maven for any android project, even if it uses only a couple of external jars? Why? If not, when is it a good a time to think about using maven in a project?

Google APIs Client Library for Java (google-api-java-client) -- Maven vs. Importing JARs

I've started work on an Android App that will work with Google Docs.
UPDATE 12/9: From the information I've come across, it seems Google Docs is not supported by this library. The question is probably still relevant in general, but seem not specifically for this project as I can't use the library anyway.
I was doing some research and come across the Google APIs Client Library for Java
I decided to start with the tasks-android-sample to begin learning how to utilize this library.
I followed these instructions
I successfully installed Mercurial and Maven and already had Java 7 installed.
I was able to execute these commands
cd [someDirectory]
hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
cd google-api-java-client-samples/shared/shared-sample-android
[editor] src/main/java/com/google/api/services/samples/shared/android/ClientCredentials.java
mvn source:jar install
I was also successful in setting up the Mercurial plugin (not sure what this did for me -- I believe the hg command above is the only time Mercurial was involved) and Maven plugin
Finally, I was able to imported the tasks-android-sample, compile it, run it on the emulator and I was able to see the tasks I created on my google account.
I then repeated the process, except this time I simply imported sample's source code and the required JARs into a new Android project and added the ClientCredentials.java manually to the project (So I could specify my Google API Key).
I was also able to compile and run this project and it operated as expected.
My questions in all this is which method is preferred? Or is it a personal choice? Are there benefits to using Maven that I'm not realizing at this time?
Maven helps you download proper dependency libraries for the project, and can reduce the burden of find and download proper libraries.
It's fine to just put dependency libs in your code base. It's a personal choice.

What benefits does Maven give (over ant) for building android projects?

I've recently been trying to setup maven for building my android projects, using the maven-android-plugin.
Whilst this is a good exercise, I'm not convinced that the benefits will outweigh the frustration in getting it working.
Can anyone give me some pros/cons on using Maven for android? I'm not looking for subjective answers, but the facts on whether its worth the effort.
Regards
Well maven is worth it if you are developing a j2ee application to save you from the jar hell
when using external apis
So if you are not going to use the maven repositories its not worth it.
I hate maven because of the problems you already mentioned. But it saves a lot time if you need xy jars. Im currently developing a eclipse plugin which can download required jars and dependencies form maven without the maven compiler or pom files. But its far from ready
You can also create a separate maven project and include it in the android project
im not sure if it works with android but you can do it in standart jdk
Maybe the gradle makes more sense.
Google released an ide called AndroidStudio, it uses gradle. Seems like google will suggest gradle in building an Android project.
I tried to use Maven to build my android project, it's hard to use, finally I changed to gradle.
Another good answer on stackoverflow why-use-gradle-instead-of-ant-or-maven
My android app shares business objects and other functionality with my back-end server so I pulled this out into a common maven project which both the app and the server (as maven projects) have a dependency on. Maven is perfect for this sort of thing, so its helpful in this instance, but if you are writing fairly straightforward apps, I'm not sure what benefit maven would have, especially when getting the android-maven-plugin to behave took me so long.

Categories

Resources