ActiveAndroid-Validation icon indicating copy to clipboard operation
ActiveAndroid-Validation copied to clipboard

How to implement with ActiveAndroid

Open kramer65 opened this issue 12 years ago • 5 comments

Hi vsigler,

I just cloned this repo and want to use it together with AA. Unfortunately I'm a bit lost in how to implement it. Where should I put the code and do I need to build it together with AA?

Any tips on this would be very welcome!

kramer65 avatar Sep 25 '13 07:09 kramer65

Ah, of course. That's one wiki page I did not add yet. In short, to build you will need to follow these steps:

  1. dowload/setup maven
  2. clone ActiveAndroid and do "mvn clean install", that will build AA and install it in the local maven repository.
  3. clone this library and also do "mvn clean install" (this library has AA in its dependencies, so you need to build AA first)

AA-Validation does not require a live android device for build (although AA does) as all is covered in regular jUnit tests.

Now, if you use maven for your project, you can just add the following dependency:

<dependency>
    <groupId>cz.sigler.android</groupId>
    <artifactId>activeandroid-validation</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

I should make the jar available somewhere.

Or if you have a classic android project, you can take the jar from "target" directory and place it in your lib directory next to ActiveAndroid jar.

After this, you can just annotate your models and use either ValidatingModel as the base class or the ModelSupportFactory.wrapModel(model) approach.

vsigler avatar Sep 25 '13 12:09 vsigler

Thanks for the explanation. Now you immediately have a good copy-paste for your wiki page.. :)

One other question. I have no experience with maven so I just installed it and tried installing AA with it. I've got this custom JodaTimeSerializer in there and also included the relevant JodaTime.jar in the libs dir. This works fine if I compile it with ant, but maven bothers me saying: package org.joda.time does not exist.

Is there no way to compile AA with AA-Validation without maven (preferably using ant)?

kramer65 avatar Sep 25 '13 13:09 kramer65

One of the great advanages of maven (or other similar "smart" build systems) is that it handles dependencies, so you don't have to store and manage them yourself.

For the yoda library, I'm not sure what version you're using. But adding the following snippet to your pom.xml of AA, just replace 1.5.2 with an appropriate version (just make sure you can find that version e.g. here: http://mvnrepository.com/artifact/joda-time/joda-time) :

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>1.5.2</version>
</dependency>

I'll add an ant script to make things easier, although I'll have to include jars of android and AA. Or maybe just add a note in the "getting started" that you need to supply those.

vsigler avatar Sep 25 '13 20:09 vsigler

I've got experience with apt-get, which I love for its simplicity and robustness. Maven has so far been quite a challenge though (see my question on SO: http://stackoverflow.com/questions/19026744/maven-complaints-about-joda-time-even-though-i-installed-it/19027078). I manually need to edit pom files, and I can't seem to figure out how to install the maven plugin for ADT.

An ant script would be greatly appreciated! :+1: Integration with the ActiveAndroid code base (and pusing it back) would be even more awesome!

Adding a note that third party jars need to be included would be fine for me.

kramer65 avatar Sep 26 '13 12:09 kramer65

Maven is not exactly a package manager. It is more of a build tool. Imagine ant, where you only need to supply minimal configuration and which, among others, will manage your dependencies for you. That means that it automatically downloads, stores and adds jars to classpath without you having to distribute them along with your sources.

Eclipse (where ADT runs) supports maven, you should be able to add it through the plugin manager.

Anyway, I've added a build.xml, so now if you supply ActiveAndroid.jar an android.jar (2.3.3+), you can build the library with ant.

vsigler avatar Oct 12 '13 10:10 vsigler