Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Adding SquiDB as a dependency

Sam Bosley edited this page Oct 28, 2016 · 15 revisions

Adding SquiDB as a dependency

The SquiDB code generator uses the Java Annotation Processing Tool, or APT. You're probably already familiar with APT, even if you don't know it--it's used by a variety of popular projects, including Square's dependency injector Dagger.

As of version 2.2.0, the Android Gradle plugin has first-class support for configuring annotation processors. The examples below use this default support, but if you are using an older version of the gradle plugin, you can also use the third-party android-apt plugin. A gradle file for a project that depends on SquiDB would look something like this:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        ...
    }
}

repositories {
    jcenter()
}

dependencies {
    compile 'com.yahoo.squidb:squidb:3.1.3'
    compile 'com.yahoo.squidb:squidb-annotations:3.1.3'
    compile 'com.yahoo.squidb:squidb-android:3.1.3'
    annotationProcessor 'com.yahoo.squidb:squidb-processor:3.1.3'
}

As you can see, you will need the squidb, squidb-annotations, and squidb-android projects as compiled dependencies, but you only need to depend on the squidb-processor project using the annotationProcessor configuration. This will prevent the processor from being included in your final apk, since it is only needed/relevant at compile time.

The SquiDB artifacts are available via jCenter, so you will need to make sure you have jcenter() in your repositories block.

Building SquiDB with j2objc for cross-platform support

For a more thorough description of how to use SquiDB as a dependency for a cross-platform library, see this wiki page.

Building from source

If you choose to clone the SquiDB repository and build from source, most of the above steps remain the same. The first change is to add the required projects to your Android Studio workspace by declaring them in your settings.gradle file:

include ':squidb'
project(':squidb').projectDir = new File(settingsDir, '../path_to_cloned_root/squidb')
include ':squidb-annotations'
project(':squidb-annotations').projectDir = new File(settingsDir, '../path_to_cloned_root/squidb-annotations')
include ':squidb-processor'
project(':squidb-processor').projectDir = new File(settingsDir, '../path_to_cloned_root/squidb-processor')
include ':squidb-android'
project(':squidb-android').projectDir = new File(settingsDir, '../path_to_cloned_root/squidb-android')

Then in your build.gradle:

dependencies {
    compile project(':squidb')
    compile project(':squidb-annotations')
    compile project(':squidb-android')
    annotationProcessor project(':squidb-processor')
}

See also: