Hosting Android Dependencies on GitHub - android

I have an Android private project (not open source) hosted on GitHub and I need to link it by an Android gradle dependency. I saw a couple of services to dot it like Jitpack.io but it's not free for private repositories. Do you know any free service to do it? Or do you know the way to host my own private project dependency?

You can use Git Submodules - it is absolutely free and quite easy to use.

I think, you have two ways to do it:
You can setup your own Artifactory server, secure it and host
your dependencies there. You should be able to publish new artifact from the GitHub repo. Nevertheless, it requires some work and machine, where you can host your repositories. I found an article regarding that at: https://inthecheesefactory.com/blog/how-to-setup-private-maven-repository/en.
You can generate *.jar or *.aar file from your library and put it manually to your project into the lib/ directory. Unfortunately, it's not so convenient like using Artifactory or Maven Central. Nevertheless, you can automate your build in such case via Bash scripts, Gradle and/or Jenkins, so manual work (like copying files) can be avoided.

In addition to the above answers, I want to add that you can host your Android artifacts on GitHub packages. and I would recommend this tutorial as a start for doing this.

Related

how to put network path for local maven repository \\user023\share\folder

We have local network with bunch of users connected together.
And we can access shared files like \\user023\share\folder\test.txt.
How can i use this address to make local maven repository or how can i use maven { url 'path to network address'} ?
Beware: Local Maven repositories are not thread safe.
If you run more than one build at the same time on the same Maven local repository, this can lead to inconsistent states.
So it is not a good idea to share a local repository between several users.
I totally agree with our colleagues that have suggested to avoid using this kind of solution:
Local repository is first of all:
Local - Its only for developer to update this repository. Its not "multi-access" safe.
Even if many threads from the same maven process try to download artifacts to it (or in general change it) this sometimes can be problematic. I'm not talking about multi-JVM concurrent access, its just not designed to be like this.
Cache - intended for fast access during the compilation and other tasks that the developers do. If you use a distributed FS it may slow down the compilation and the developers won't use it.
So if your goal is to
i need to publish my library on server and other user use it to build project
Use tools like Nexus or Artifactory to host your artifacts intended for shared usage
If these tools are not available - use some web server with HTTP access and configure maven to download from there.
If this is impossible - instruct the developers to run mvn install per new version of the shared resources. Then they'll get in their local repo an application of the reproducible version.
Of course the option 3 is a really bad one, option 2 is much better, but option 1 is the best one you can get.
Quite simply:
maven { url 'file:///[Path-to-Repo]'}
For example:
If you repo were located at '\\Sever\Developer Repos\m2':
The Maven reference in the repository section of your build.gradle would look like:
maven { url 'file:///Sever/Developer%2520Repos/m2'}
A few caveats:
It is advised to do what other suggest and setup a 'real' repository.
if that is not possible, then enter into the rest of this at your own
risk.
Use the '/' character in your paths.
Spaces in filenames need to be designated with their unicode escaped equivalency.
The m2 repo needs to be an actual Maven repo with the appropriate file structure,.pom files etc.
Never WRITE to a repo like this with a build script when there are multiple users utilizing this repo. This will most certainly cause corruption for at least a portion of the repo. In fact, I would lock the file structure as read-only if possible to prevent this from happening and force manual updates to the repo as necessary.
This information is for gradle 6.3 with the Android 3.6.3 gradle build tools. This has broke in the past and so be sure to use a gradle wrapper with your project to ensure build compatibility as you move forward.

How to post an Android Studio .AAR file to a local Artifactory repository

I'm using Android Studio 1.5.1 to build a self-contained library (no external dependencies). Let's call it "myLib.aar".
I've been asked to modify my Gradle build to push the .AAR file into the company's private, local Artifactory repository. I am an experienced developer but know very little about Java repositories.
There are a lot of search hits on this topic, but none of them have so far resulted in a solution for my particular situation. Even more troubling, I can't find any two posts that implement a solution the same way.
I'm further confused why one can't just use an/the Artifactory plugin. Apparently one must ALSO use a Maven plugin -- but why? Some use third-party Maven plugins, some use something which appears to be built into Android Studio.
So my question is simply what lines to add to which Gradle files in order to push my .AAR file into Artifactory?
You should use Artifactory plugin.
Re Maven plugin. The role of Maven plugin is to generate metadata about your package (the pom.xml file). Other option is using Ivy plugin to generate the metadata in an alternative format (the ivy.xml file). One way or another your package needs metadata. Select one of them (by applying maven, maven-publish, ivy, or ivy-publish plugin).
The instructions about Artifactory plugin show configuration examples for all the possible options.
JFrog GitHub repo contains project examples for all the possible options.
Hope that helps.
I am with JFrog, the company behind Bintray and [artifactory], see my profile for details and links.

Hosting Gradle artifacts on GitHub

I know that people use GitHub to deploy Maven artifacts (in a new branch) but since we are using Gradle I would like to know if there is a simple way of handling those dependecies as well?
We have different little projects that are independent but used by our main project and we want to manage those dependencies without including them locally.
Thank you.
There is an unofficial gradle plugin called Gradle Git Repo plugin that claims to do what you're looking for. Note however, that I did not play with it myself to verify that it works.
You could use JitPack to include your GitHub projects as dependencies. The idea is that JitPack provides a Maven repository where each package comes from a GitHub project.
It doesn't require that you upload files so it's quite easy to use. Instead when you request a file it builds it from source code.
There are two requirements to start using:
1. You need to have a build file in your project (Gradle or Maven)
2. You shoud create a GitHub release so that your project gets a version

Sharing a library or reusing it in another project

Using android studio 1.0 for my project, I plan to code a library module inside it. But I am wondering whether sharing only the library module (for example in its own github repository) is easy : I mean, someone fetching this repository, can integrate it as a library module in its own project easily. Also, does the library module has to define at least an activity, or can it just contain independents classes and resources ?
Of course, I also plan to share the global project on a github repository.
So what is the "safest" and easier way to proceed ?
Apologizing if the question may seem too obvious or bad explained.
The only real way to separate a project into multiple git repositories is through submodules. It's not a bad concept, but what it effectively means is that you have a git repository inside another. One the remote side, they are separate repositories with one being included via submodule.
More information, and the command line tools you'll need to get started can be found at: http://git-scm.com/book/en/v2/Git-Tools-Submodules
Note, there is a lot of hate for submodules, and some of it is earned. It's not intuitive and is often considered an expert Git feature. For that reason, I recommend you read it thoroughly and make sure you understand. Perhaps even throw together a couple of unrelated repositories to play with. BTW, you can have a git repository on your computer anywhere (git init --bare to create it). Then you can clone it anywhere else with git clone file:///<your-path-here> Thus your local and remote are on one computer so you can play/learn without having to create more repositories on git hub or some such.
Since you are using Android Studio, I assume you use Gradle as the build system. With that assumption, below are my answers:
Your library project needs not have Activity, but will need AndroidManifest.xml and a Gradle project layout (src, res folder etc).
If your library project is hosted on Github (or locally outside the root folder of the main project you plan to use it), then you can use Git submodule like lassombra suggested to bring it under root folder of main project.
Once you have the library under the root folder of your main project, you can use Gradle multi-project setup to link them.

Duplicate file when deploying apk

This problem seems to come up for a few people, but I haven't been able to apply the solution suggested in other threads for one reason or another so...
I am trying to build a simple android app with an embedded webserver. The server of choice if jetty. I am using maven to manage dependencies with the maven-android-plugin. I have added jetty-server v8.x as a dependency with the default scope. When I try and deploy my apk to the sandbox I get an error
Found duplicate file for APK: about.html
So the file in question is from the jetty package, or rather it is found in two jetty packages, one being a dependency of jetty-server. Other threads out there seem to be suggest I delete the file from one jar or the other but this is not really a scalable solution as I am not the owner of the jars.
Is there a more general solution to this problem? Something that manages the conflict and build or deploy time?
I should note, I am a bit of a Java noob, and have gone the NetBeans and maven route because this is the toolkit I'm familiar with.
OK, found it. The solution is to build using the following command
mvn android:deploy -Dandroid.extractDuplicates=true
There are a couple of issues:
First, to integrate Jetty, your project is going to need a pom.xml file. The Android APK (as-is) does not know how to resolve a pom with Maven dependencies without some sort of bridge. So, you'll need to install a few plugins for Pom management onto Eclipse. Follow the instructions here: http://rgladwell.github.com/m2e-android/
(I found it easier to create a new project using the method described here rather than converting my existing Android app to a Maven project, but I'm sure it'll work either way.)
Second, once you've installed this, you're going to have to make sure your pom.xml contains the necessary dependencies, build goals, and variables. So, open up your pom.xml, and make sure you have the following:
In the "build" node:
sourceDirectory -> src
defaultGoal -> install (I suppose...)
In the "dependencies" node:
... all the jetty/cometd dependencies (org.cometd.java, org.eclipse.jetty, etc.)
Third, you should know that you can't just click the green run button and launch the app via ADB. You have to install it the maven way (Run As -> Maven build/install/test/whatever)
You should open up your war file and check if you actually have two about.html files in there. Some time ago I had two web.xmls in my war files. If you actually have duplicates then you should try to exclude those files.
Maybe you have one file in your project and the duplicate is generated by the maven plugin.
I also just realized that you're probably already properly using the android-maven plugin. One other important tip: change the scope to runtime on the jetty dependencies. This builds successfully for me, whereas using the default scope (compile) always threw the duplicate file in APK error.

Categories

Resources