Skip to content

Commit

Permalink
Updated Android docs with text from #65
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Fontaine committed May 5, 2016
1 parent 4d2dc41 commit 7d2b080
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
39 changes: 32 additions & 7 deletions documentation/api/index.html
Expand Up @@ -90,20 +90,45 @@ <h2>Programmatic Configuration (Java)</h2>

<h2>Programmatic Configuration (Android)</h2>

<p>Start by adding the <a href="https://github.com/SQLDroid/SQLDroid">SQLDroid</a> driver jar to the
<code>libs</code> directory</p>
<p>In order to use Flyway on Android you have to add flyway-core as well as SQLDroid as dependencies. There are two things to keep in mind with Android: First, you have to load the migrations as <i>assets</i>, not <i>resources</i> and second, you have to let Flyway know your Android context, by calling <code>ContextHolder.setContext</code>.</p>

<p>1. Add the necessary dependencies to <code>build.gradle</code>:</p>

<pre class="prettyprint">dependencies {
// Your other dependencies
// ...

compile 'org.flywaydb:flyway-core:{{ site.flywayVersion }}'
compile 'org.sqldroid:sqldroid:1.0.3'
}</pre>

<p>2. Make source that your migrations are included as assets (notice that assets have to be declared in the project itself and not in a dependency. But you can use reference e.g. <code>'../lib/src/main/resources'</code> to use the resources of a lib project)</p>

<pre class="prettyprint">android {
// SDK, config, buildTypes, etc
// ...

sourceSets {
// Place your db/migration folder here
main { assets.srcDirs = ['src/main/assets'] }
}

// ...
}</pre>

<p>3. Include the setup in your main activity onCreate or application onCreate:</p>

<p>Then inside your main activity add this:</p>
<pre class="prettyprint">import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.android.ContextHolder;
import android.database.sqlite.SQLiteDatabase;
import org.sqldroid.DroidDataSource;

...

SQLiteDatabase sqLiteDatabase = openOrCreateDatabase("...", 0, null);
DroidDataSource dataSource = new DroidDataSource(getPackageName(), "...");
ContextHolder.setContext(this);
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:sqlite:" + sqLiteDatabase.getPath(), "", "");
flyway.setDataSource(dataSource);
flyway.migrate();</pre>
<p>Now add your migrations to the <code>assests/db/migration</code> directory and you're done!</p>

<h2 id="spring">Spring Configuration</h2>

Expand Down
8 changes: 7 additions & 1 deletion documentation/releaseNotes.html
Expand Up @@ -122,6 +122,12 @@ <h3>Bug fixes</h3>

<h3>Documentation fixes</h3>
<ul>
<li>
<a href="https://github.com/flyway/flywaydb.org/pull/65">Issue 65</a>
Rewrite Android documentation to fit Android Studio/Gradle and SQLDroid better
<span class="label label-info"><a href="https://github.com/flyway/flywaydb.org/pull/65"><i
class="fa fa-mail-reply"></i> Pull Request</a></span>
</li>
<li>
<a href="https://github.com/flyway/flywaydb.org/pull/66">Issue 66</a>
fix sbt version
Expand Down Expand Up @@ -149,7 +155,7 @@ <h3>Documentation fixes</h3>
<p>
Thanks to alekseevIN, Antti Lampinen, Artem Konenko,
Aurélien Mino, azalesky, Erin Drummond, fromi, Gili Tzabari,
hntran8, J. Taylor O'Connor, Jeff Johnston,
hntran8, J. Taylor O'Connor, Jeff Johnston, Johannes Brodwall,
Kari Häkkinen, Kenji Yoshida, Kevin Wimmer, krispii, lrozenblyum, Maksim Serebro, Marat Abrarov,
mezuzza, Nathan Vick, Nick Strecker, Renat Sabitov, sourcesmith, Sten Røkke, tsbx, Walter Gillett
and Werner Mueller for reporting these issues and contributing fixes.
Expand Down

0 comments on commit 7d2b080

Please sign in to comment.