anko README

The project's README from github.com/Kotlin/anko. As one markdown file: README.md.

obsolete JetBrains project Download GitHub license

Anko logo

:warning: Anko is deprecated. Please see this page for more information.


Anko is a Kotlin library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.

Anko consists of several parts:

Anko Commons

Anko Commons is a "toolbox" for Kotlin Android developer. The library contains a lot of helpers for Android SDK, including, but not limited to:

Anko Layouts (wiki)

Anko Layouts is a DSL for writing dynamic Android layouts. Here is a simple UI written with Anko DSL:

verticalLayout {
    val name = editText()
    button("Say Hello") {
        onClick { toast("Hello, ${name.text}!") }
    }
}

The code above creates a button inside a LinearLayout and attaches an OnClickListener to that button. Moreover, onClick accepts a suspend lambda, so you can write your asynchronous code right inside the listener!

Note that this is the complete layout code. No XML is required!

Anko has a DSL for ConstraintLayout since v0.10.4

Hello world

There is also a plugin for Android Studio that supports previewing Anko DSL layouts.

Anko SQLite (wiki)

Have you ever been tired of parsing SQLite query results using Android cursors? Anko SQLite provides lots of helpers to simplify working with SQLite databases.

For example, here is how you can fetch the list of users with a particular name:

fun getUsers(db: ManagedSQLiteOpenHelper): List<User> = db.use {
    db.select("Users")
            .whereSimple("family_name = ?", "John")
            .doExec()
            .parseList(UserParser)
}

Anko Coroutines (wiki)

Anko Coroutines is based on the kotlinx.coroutines library and provides:

Using Anko

Gradle-based project

Anko has a meta-dependency which plugs in all available features (including Commons, Layouts, SQLite) into your project at once:

dependencies {
    implementation "org.jetbrains.anko:anko:$anko_version"
}

Make sure that you have the $anko_version settled in your gradle file at the project level:

ext.anko_version='0.10.8'

If you only need some of the features, you can reference any of Anko's parts:

dependencies {
    // Anko Commons
    implementation "org.jetbrains.anko:anko-commons:$anko_version"

    // Anko Layouts
    implementation "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
    implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"

    // Coroutine listeners for Anko Layouts
    implementation "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
    implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"

    // Anko SQLite
    implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
}

There are also a number of artifacts for the Android support libraries:

dependencies {
    // Appcompat-v7 (only Anko Commons)
    implementation "org.jetbrains.anko:anko-appcompat-v7-commons:$anko_version"

    // Appcompat-v7 (Anko Layouts)
    implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-coroutines:$anko_version"

    // CardView-v7
    implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"

    // Design
    implementation "org.jetbrains.anko:anko-design:$anko_version"
    implementation "org.jetbrains.anko:anko-design-coroutines:$anko_version"

    // GridLayout-v7
    implementation "org.jetbrains.anko:anko-gridlayout-v7:$anko_version"

    // Percent
    implementation "org.jetbrains.anko:anko-percent:$anko_version"

    // RecyclerView-v7
    implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"

    // Support-v4 (only Anko Commons)
    implementation "org.jetbrains.anko:anko-support-v4-commons:$anko_version"

    // Support-v4 (Anko Layouts)
    implementation "org.jetbrains.anko:anko-support-v4:$anko_version"

    // ConstraintLayout
    implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
}

There is an example project showing how to include Anko library into your Android Gradle project.

IntelliJ IDEA project

If your project is not based on Gradle, just attach the required JARs from the jcenter repository as the library dependencies and that's it.

Contributing

The best way to submit a patch is to send us a pull request. Before submitting the pull request, make sure all existing tests are passing, and add the new test if it is required.

If you want to add new functionality, please file a new proposal issue first to make sure that it is not in progress already. If you have any questions, feel free to create a question issue.

Instructions for building Anko are available in the Wiki.

anko (Kotlin/anko)

Searching Database…

15.8K ·GitHub
archived
What is this?Anko is a Kotlin library that makes Android application development faster and easier: it keeps your code clean and readable and hides the rough edges of the Android SDK designed for Java.
Is it one big library or a set of modules?A set of four: Anko Commons (helpers for intents, dialogs, logging and more), Anko Layouts (a DSL for dynamic layouts), Anko SQLite (a query DSL and parser collection) and Anko Coroutines (utilities over kotlinx.coroutines).
How do I add Anko to my Android app?In a Gradle project add the meta-dependency — it plugs in all parts (Commons, Layouts, SQLite) at once — or reference only the parts you need. Non-Gradle IntelliJ projects attach the JARs from jcenter as library dependencies.
Do I need anything besides a normal Android project to use it?Just a Kotlin Android setup: Anko is written in Kotlin, and its coroutines module builds on the kotlinx.coroutines library, which comes along as a regular dependency.
Is Anko still a safe pick for new projects?Not really — Anko is deprecated and the repository is archived, so it is best suited to maintaining existing apps rather than starting new development. The README links to a page with more information.
Can I write layouts in Kotlin instead of XML?Yes — Anko Layouts is a type-safe DSL for dynamic Android layouts, and the README stresses that the DSL snippet is the complete layout code: no XML required. A ConstraintLayout DSL has been included since v0.10.4.
Can I preview Anko layouts visually while coding?Yes — there is a dedicated Android Studio plugin that supports previewing Anko DSL layouts.
What does Anko offer for working with SQLite?Anko SQLite provides a query DSL, parsers and helpers that spare you from manually parsing cursor results — fetching a list of users with a particular name takes just a couple of lines.
How does it handle background and async code?Listeners like onClick accept a suspend lambda, so asynchronous code can sit right inside them. Anko Coroutines also adds bg() to run code on a common pool and asReference() to keep non-cancellable coroutines from leaking captured objects.
Creator
Kotlin
Size
14.9 MB
Stars
15.8K
Age
12y
Commits · 90 Days