Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Using with other annotation processor #22

Open
larten opened this issue Feb 9, 2015 · 13 comments
Open

Using with other annotation processor #22

larten opened this issue Feb 9, 2015 · 13 comments

Comments

@larten
Copy link

larten commented Feb 9, 2015

Hello,

butterknife is a default library to development, so I must use it!

But I would like to use json parser.

And this part of gradle block butterknife:

compileJava {
  doFirst {
    // Directory should exists before compilation started.
    generatedSourcesDir.mkdirs()
  }
  options.compilerArgs += [
                       '-processor',
                       'com.instagram.common.json.annotation.processor.JsonAnnotationProcessor',
                       '-s',
                       generatedSourcesDir
  ]
}

What is the proper way to use both libraries together? Others recommended to use ig-json-parser with android-apt but I don't know how can I.

bg,
Larten

@ttung
Copy link
Contributor

ttung commented Feb 9, 2015

What happens when you combine the two?

@larten
Copy link
Author

larten commented Feb 9, 2015

Butterknife doesn't working.

@TommyVisic
Copy link

I'm using both together without a problem. I don't believe I had to make any changes either. Have you confirmed that IG JSON Parser is working properly on its own?

@larten
Copy link
Author

larten commented Feb 9, 2015

My json models are in the android app module and if gradle task for ig-json-parser is uncommented, than it's generate correctly the models and I get NullPointerException for every view, but if I comment this, than work.

@TommyVisic
Copy link

I think you need to put IG parser in its own module. Now that I think about it, I did run into an issue w/ the java gradle plugin causing some kind of incompatibility when merge with the main build.gradle. I know the IG folks use the parser in this way too as not to expose the models' members with default visibility. Here's how we have it set up.

screen shot 2015-02-09 at 10 40 54 am

@larten
Copy link
Author

larten commented Feb 9, 2015

Okay, maybe it will be good, but now my classes don't see generated files in model modul.
Could you share this part of your gradle script?

@TommyVisic
Copy link

settings.gradle

include ':tastemade'
include ':tastemade:jsonModels'

app module build.gradle

apply plugin: 'android'

android {
    ...
}

dependencies {
    compile 'com.jakewharton:butterknife:5.1.2'
    compile project(':tastemade:jsonModels')
    ...
}

jsonModels module build.gradle

apply plugin: 'java'

ext {
    generatedSourcesDir = file("gen-src/main/java")
}

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
    }
    gensrc {
        java {
            srcDir 'gen-src/main/java'
        }
    }
}

compileJava {
    doFirst {
        // Directory should exists before compilation started.
        generatedSourcesDir.mkdirs()
    }
    options.compilerArgs += [
            '-processor',
            'com.instagram.common.json.annotation.processor.JsonAnnotationProcessor',
            '-s',
            generatedSourcesDir

    ]

    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
    compile 'com.instagram:ig-json-parser-processor:0.0.3'
}

@szoszig
Copy link

szoszig commented Feb 10, 2015

Hello,
I have the same problem.
I did everything you wrote, but my app modul can't see the properly generated helper methods, just the models I wrote.
Do you have any advice?

thx,
Szöszi

@larten
Copy link
Author

larten commented Feb 13, 2015

I have same problem :(

@ttung
Copy link
Contributor

ttung commented Feb 18, 2015

Sorry for the late response. Generally, we do indeed put the models in separate modules to avoid inadvertent access to package-privacy fields. However, there should be nothing that requires that behavior.

Unsure what's going on with the interaction with Butterknife, I will try it out when I get a chance.

In the meanwhile, I pushed a change so that the jar file tells the compiler how to invoke the annotation processor. Maybe that will help the issue? LMK!

@ttung
Copy link
Contributor

ttung commented Feb 18, 2015

Specifically, 86f29b5

@szoszig
Copy link

szoszig commented Feb 18, 2015

Sorry, but it's the same.

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants