GithubHelp home page GithubHelp logo

mdumrauf / annotation-processor-with-java8-jack-and-jill-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nickcellar/annotation-processor-with-java8-jack-and-jill-android

0.0 1.0 0.0 131 KB

Android Annotation Processor With Java8 and Jack&Jill

Java 100.00%

annotation-processor-with-java8-jack-and-jill-android's Introduction

Android Annotation Processor
With Java8 and Jack&Jill CircleCI

Just a project to try out Android Annotation Processor in the new Java8 and Jack&Jill enviornment. Also check if libraries and testing frameworks work with it.

First of all, make sure you know what is JACK&JILL. Check this talk about The Jack and Jill Build System on Youtube.

Supported tools

  • Instant Run
  • Data Binding (android.dataBinding.enabled = true will fail)
  • Minifying For Tests (Enable proguard for release and set testBuildType 'release' will fail)

Libraries

  • Dagger 2.4
  • Dagger 2.5 (classpath 'com.google.guava:guava:19.0' needed)
  • AutoValue 1.2
  • Butterknife 8.1.0
  • LoganSquare 1.3.6

Testing frameworks

  • JUnit 4.12
  • Robolectric 3.1
  • Mockito 1.10.19

Project Set Up

/build.gradle

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-alpha4'
    }
}

/app/build.gradle

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.0'
    defaultConfig {
        targetSdkVersion 24
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Sample Dependencies

dependencies {
    // dagger 2
    compile 'com.google.dagger:dagger:2.5'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.5'
    // auto-value
    compile 'com.google.auto.value:auto-value:1.2'
    annotationProcessor 'com.google.auto.value:auto-value:1.2'
    // butterknife
    compile 'com.jakewharton:butterknife:8.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
    // logan square
    compile 'com.bluelinelabs:logansquare:1.3.6'
    annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.6'
}

Issues

Stream API Only Supported In Android N

It is only supported if you set minSdkVersion to 24 or above.

Instant Run Not Supported

It is simply not supported now. Notification will be shown whenever you try to use it.

Data Binding Not Supported

If you put the following, error will be thrown.

android {
    dataBinding {
        enabled = true // Error: Data Binding does not support Jack builds yet
    }
}

Minifying For Tests Not Supported

If you put the following, error will be thrown.

Error:A problem occurred configuring project ':app'.
> Minifying the variant used for tests is not supported when using Jack.
android {
    testBuildType 'release'
    buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.debug
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Java 8 Stream API Not Working (fixed since 2.2.0-alpha4)

Stream api is not working working after upgrading to 2.2.0-alpha3, follow ticket. It means the following doesn't work:

Arrays.asList(3, 1, 2).stream()
    .sorted()
    .map(String::valueOf)
    .forEach(integer -> view.setText(view.getText() + " => " + integer));

Incorrect location for code generation (fixed since 2.2.0-alpha4)

Classes are generated in build/intermediates/classes/ instead of build/generated/source/, so they are not treated as source by Android Studio. Code referencing them will be displayed red. This issue has a temporary solution

Change Log

2016/6/25 - Android Plugin Updated

  • Updated android plugin version to com.android.tools.build:gradle:2.2.0-alpha4.
  • Extra dependency com.google.guava:guava:18.0 is no longer needed
  • Java 8 stream api is fixed.
  • Classes are generated in build/generated/source/apt now.
  • compileSdkVersion is updated to 24
  • buildToolsVersion is updated to 24.0.0
  • targetSdkVersion is updated to 24

2016/6/13 - Android Plugin Updated

  • Updated android plugin version to com.android.tools.build:gradle:2.2.0-alpha3.
  • Java 8 stream api is no longer working.
  • Ticket filed.

2016/6/2 - Temporary Solution

  • Added script to temporarily place generated code into source directory.
  • See here: gist
  • Alternative with gradle plugin. See changes in a pull request

2016/6/1 - Android Plugin Updated

  • Updated android plugin version to com.android.tools.build:gradle:2.2.0-alpha2.
  • Extra dependency com.google.guava:guava:18.0 is still neccessary. Ticket filed.
  • Classes are generated in a bad location build/intermediates/classes/

2016/5/23 - After Google IO

  • Testing code using Java8 with Annotation Processor from com.android.tools.build:gradle:2.2.0-alpha1.
  • AndroidN must be targeted and latest build tool 24.0.0 rc4 must be used to work.
  • It is working but generated code cannot be recognized by Android Studio.
  • Extra library is needed to work -> com.google.guava:guava:18.0.
  • Classes are generated in build/intermediates/classes/ instead of build/generated/source/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.