As you can see from my passed 3 questions I am having major problems with my project setup. I am getting lots of very specific errors that seems like nobody can answer them. I am getting hugely frustrated. So I am going to try a fresh approach. I will describe how I would like my project set up and if somebody could give me some brief steps to follow I would be very grateful. After messing around with this for around a week I believe I have some knowledge but maven seems to be incredibly difficult to understand.
I am writing a library which will be used in 2 projects. The major libraries I would like to use are roboguice, robolectric and jackson(json library). I would like to have a way to test the library but I am unsure if this should be in a different module or not. Robolectric seems to suggest it should be in the same module. I am unsure how I should use this library in the other 2 projects. I have been looking at this http://code.google.com/p/maven-android-plugin/wiki/ApkLib but unfortunately the website tells me next to nothing about how I should create the apklib.
If it is possible I would also like the other 2 projects to have a dependency on that library and build it automatically.
I have been using this site to create the maven project http://stand.spree.de/wiki_details_maven_archetypes
But I have been running into issue after issue. If anybody can point me in the right direction I will be very appreicative
Even if maven is (almost) a foreign country to me, I had some moderate success setting up a maven project and interacting with it using intellij. I wanted to use it because it looked the easiest way to have robolectric working with intellij.
I wrote a blogpost you can find here
What you need is:
Maven android sdk deployer https://github.com/mosabua/maven-android-sdk-deployer
Maven android plugin http://code.google.com/p/maven-android-plugin/wiki/GettingStarted (using android archetypes is just fine)
If you want to build an apk lib instead of an apk, just specify apklib in the packaging tag
PS: I also saw this a while ago, but never gave it a try.
Related
I'm a beginner in Android programing, and I'm working with android studio...now i wander what is the best way for installing open sources libraries from gitHub.
my question is from organization principles point of view-
should i create a new package for every library and put all the library source code as is in that package? should the package be in the source.main.java folder?? (the one that the android studio creates automaticly).
sorry for the dumb question...it's just that im taking my first baby steps in a big scale program and i don't want to loose my head in the future because of bad organization practices.
There's no right answer to this question. A few wrong ways to do it, but common sense will guide you.
My advice:
Start by having the source of this open source code checked into your company's source control system somewhere and capable of being built or re-built as needed. Not necessarily in your project, but just getting the code checked in so it can't be lost or confused with the original author's ever evolving changes on GitHub.
As to how you consume it, you have several options.
Build the open source in it's own project (checked into source control, but separate from your main project). Then just take the drop of compiled files (.class, .jar, .lib, etc...) and check that into your main project. This is the most flexible option if you don't think you are ever going to need to change the open source code that often. Has the side benefit of being managed for several projects.
Drop the source code as-is directly into your project. This means you will always be rebuilding the code. This gives the most flexibility with evolving and changing the the code specific to your project needs.
There's probably hybrid solutions of these options as well.
The bottom line is that whatever you use needs to be copied and building in your own system. Because the code you pulled down from GitHub could go away or change significantly at any time.
A simple solution would be to use JitPack to import those GitHub projects into your gradle build.
First you need to add the repository:
repositories {
maven { url "https://jitpack.io" }
}
and then all the GitHub repositories as dependencies:
dependencies {
compile 'com.github.RepoOwner:Repo:Version'
// more dependencies...
}
Behind the scenes JitPack will check out the code and compile it.
I think you are looking for this. If you are using eclipse, you should check this
If you are looking for adding jar file to your lib, you can simply create a lib folder in your project and add jar file into the library and you must add the line compile files('jarfile.jar') in the build file(gradle build). If you are using eclipse you can follow this
By the way, creating a package for each library and putting all library source codes doesn't look sane to me. It is almost equivalent to recreating the project. I'm sure that it is not the proper approach.
If the third-party code is packaged as a .jar or a .aar and made available in public-facing maven repository (e.g. maven central), then you should add the library as a dependency in your build.gradle file.
If it is not available as a maven/gradle dependency, you could add the library's code to your project as suggested in other answers here. I have never liked that solution at all.
You could also build the .jar or .aar and add that to your project's lib directory, as also suggested by other answers here. For a small, simple project with few dependencies, that might make sense.
What I like to do for larger, longer-lived projects, is to set up my own Nexus server (a Maven repo server), and put the third-party dependencies there.
I have more than 64K functions on my Android application and I want compile it and it's not possible in a 'normal' way. Searching over the network I've found some esotheric hacks to fragment the dex file and achieve compile the program.
Recently google has released the support for multidex and I expected that finally I can generate the program without tricks and hacks. But seems that I want a miracle o something similar. I've created my application that extends a MultiDexApplication that seems the solution to do this but I don't found the form to say to Eclipse that fragments the dex file properly. Somebody knows how to resolve this problem.
I'm using Eclipse with no Maven and no Gradle.
Thanks
Edit 10/27/2014 : I fixed the problem using Eclipse + Android Maven Plugin. People has fixed the problem using Android Studio + Gradle. I expect that in the future this problem will be fixed using only Eclipse because do a make maven install and maven deploy every time is too slow.
I have been working on Android applications for a while now. One problem I faced quite often is that new people have trouble keeping up with all the dependency of library projects. Things went from bad to worse with my latest project, which we use 7 libraries (2 developed in-house and a lot of open-sources). Right now we are using both Bitbucket and Github for our solution.
Is it possible to just combine all the projects under one Git repo? So we can just clone one and start working right away while maintaining the connection to the original repo of those open-source project.
For instance, it uses ActionBarSherlock, FacebookSDK, SlideMenu, etc.
If not, would Maven solve this problem?
Submodules are the solution to this problem.
You would add the repositories of those libraries as submodules to the repository of your app.
Yes. Assumed you have your 'main' project already setup and your local reg setup, and EGit.
Eclipse->rightclick on library project -> Team -> SharePrject-> git-> set Reg as the one your main is contained. If its a lib, then I suggest leave 'Path within reg' alone. ->finish.
You will get a bunch of errors. This is because the physcial location of the project has moved to the reg. Fix dependencies->Relink libraries( ex support-v4) -> readd library projects-> commit.
And of course don't forget to back up before doing anything.
I'm evaluating whether to use Ant or Maven to automate my build process for Android development. I've been trying to read online to make an informed decision, but haven't found many specifics that relate to Android development. Based on your experience:
What are the main differences ?
I've read some people saying they have different purposes ? What would those be ?
What would make you pick one over the other ?
What are the strong points and weaknesses of each ?
Which is easier to setup and maintain ?
Is there one that is proffered/most used in the community ?
I found a similar question What benefits does Maven give (over ant) for building android projects?, but he was asking about the
benefits of Maven over Ant and, first, I don't even know the Ant benefits and, second, he just got one answer that didn't make things clear for me.
I use Intellij, just in case it makes any difference though I hope it doesn't.
If you can use Maven, go with Maven. And, don't you dare try to change the standard directories! Heck, even when we use Ant, I insist we setup the directories like Maven. That way, new developers know where things are, or have to trace through the build.xml to find where things are located. The other things is that if you do use Ant, you should also use Ivy. That way, you get the Maven dependency handling within Ant.
The big irony is that once we use Ant and Ivy, and stick to the standard Maven directory structure, moving from Ant to Maven is a cinch. But, the need to move to Maven is lessened too. Our build.xml is clean and simple to understand. All the files are in the right place. Builds are quick, simple, and easy to maintain. Who needs Maven?
The problem is once we've reach this state of Nirvana, is to keep the project from heading back to the State of New Jersey. Developers start carving out exceptions in our build.xml. Don't compile this *.java file. Move this *.xml into our java directory, put test code under the main directory, but we'll put the name test in the file, so we know it's test code... New and complex things are done. And, somehow, we're back in Secaucus.
So, once I've got my Ant project clean and neat enough to move to Maven, I make the leap.
One more thing: Maven makes it very, very simple to copy a project from one computer to another. Maven handles all the dependencies stuff -- even the build stuff. No more, you need AntContrib, or you need to download the hibernate Ant tasks. If you need something, it'll download itself. It's one of the big reasons Maven is so popular with many open source sites.
My big complaint about Maven is that it's so poorly documented. There's a Wiki, but almost no content, and very few manuals.
I've not used Ant or Maven much for Java recently, but I can tell you the main differences between them -- it basically boils down to automated conventions (Maven) vs. absolute flexibility (Ant).
Maven will do almost everything for you, but it's much easier to use if you arrange your projects to suit it. It'll handle dependency tracking and resolution, building, packaging and storing the built packages, while also helping with branch maintenance and release engineering. I find it an awful lot easier to release my (flex) projects that are built with Maven.
Ant is much more flexible. You can do whatever you want, build in whichever way you want. If you have pre-existing projects, you can automate much of what your IDE is doing without changing anything else. It doesn't hand-hold as much as Maven, which also makes it easier to diagnose when things go wrong... You're on your own for dependencies, branches and releases, though. Where we use ant, we use it because we had a project set up which we wanted to automate, and Maven wouldn't adapt to fit it. If you need to do something not supported by Maven, Ant may be your only hope.
Personally, I'd use Maven over Ant if possible, but I'd admit that it's not always possible.
Consider using Gradle!
It combines the best from Maven (convention over configuration) with the best from Ant (the flexibility and the huge library of pre-made tasks).
A Gradle build is written in Groovy, so you have the full power of a scripting language at your fingertips!
There is an Android plugin for Gradle. I haven't used it though, so I cannot tell if it's good or not.
See http://www.gradle.org
I agree with Andrew's answer in its entirety. However, I would note that the maven support is not supplied by the android SDK team. It's provided by a third party. Now, they are an active participant, but it still means that there may be a delay in getting support for the very latest features.
That said, I don't particularly like the ant support provided by the android SDK team. If you run android create project you'll end up with a build.xml that recommends you copy paste chunks of XML in order to customise it. This makes it burdensome to move to a new version of the Android SDK.
Overall, I suspect that moving to maven will be easier to maintain over the long run.
I may have bitten off more than i can chew here. I've moved outside of my .net / visual studio comfort zone for the first time in order to play with the Android SDK. I'm (attempting) to use IntelliJ.
I have a single module project. I want to "reference" the google gson library. After hours of tooling around in the project structure dialog, googling, reading the IntelliJ help and laughing at my own ineptness I managed to at least get a successful build.
However when i deploy to the virtual device, I note the "logcat" shows:
Could not find class
'com.google.gson.Gson', referenced
from method
com.example.HelloW$ClientThread.run
I'm assuming this is less to do with my code, and everything to do with how i ended up referencing the gson-1.7.1.jar file?
Can somebody tell me in the simplest terms how i add that dependancy successfully?
Adding jar file to Dependencies is easy and you can find the details in the official documentation.
Make sure that the library scope is set to Compile.
Here is the sample showing "lib" library that contains a couple of jars added to the module dependencies: