sockeqwe / sqlbrite-dao

DAO for SQLBrite
http://hannesdorfmann.com/android/sqlbrite-dao
Apache License 2.0
182 stars 22 forks source link

Is DAO jar pushed to central? #24

Closed harinair closed 8 years ago

harinair commented 8 years ago

Somehow DAO does not show up in my dependencies and all the Dao classes show as missing in build. 0.2.2 works but when I switch to 0.4.0 or 0.4.1, I cannot compile. I tried everything :-(

sockeqwe commented 8 years ago

Yes it is pushed to maven central. There was a similar issue reported by someone else with a previous version #19 . I think it's a AndroidStudio problem. From time to time I have noticed that Android Studio can't resolve dependencies if there are compile errors. Note that migrating from 0.2 to 0.4 there were some api changes. If that doesn't help, try to clean your project, and delete the content of your build folder.

harinair commented 8 years ago

There is something really wrong. dao 0.2.2 only works for me. I deleted all build dirs, deleted gradle cache and even cleaned/rebuilt the project. But whatever I do to change dao ver to 0.4.0 or 0.4.1, the Gradle sync process completes but does not add com.hannesdorfmann.sqlbrite.dao or com.squareup.sqlbrite classes. I am adding sqlbrite/sqlbrite-dao as dependency to a module in my project.

sockeqwe commented 8 years ago

Hm, pretty strange!

I have exported the sample project into an own git repo: https://github.com/sockeqwe/SqlBriteDaoSample

Can you check it out and import it in android studio on your local machine and verify that it compiles / runs?

harinair commented 8 years ago

This is the weirdest thing I have experienced in my whole programming life. Normally I solve all of the things by myself... if I ask for help then it is really F***ed-up. So, good news: I solved it... Your sample project worked fine and I doubted it may be because I have multiple modules in my project. Hence I created another module in your project and moved all DB related stuff into that... that also worked!!! I suspected android sdk version, dagger version (I use Dagger2), etc. I upgraded the SDK to match yours. Still problem persisted.

So I assumed that it may be a chicken or egg problem: It is not adding the DAO package if there is a compile error and I cannot fix compile errors without DAO package! And my assumption was right! I had to painfully comment out all of my DAO code. Ran the compile successfully and voila! the DAO package and SQLBrite got added. Now I went ahead uncommented the code and fixed the errors related to your API changes. Now everything is Ok. You may have to fix this weirdness.. and I frankly don't know how you can do this; otherwise upgrading becomes a nightmare.

sockeqwe commented 8 years ago

I don't think I can fix that. I faced this kind of issue also with other annotation processing based libraries like dagger2. It's a gradle android plugin issue I guess. The problem is that if you have a compile error in your code, android studio will not only display that single compile error, but the whole list of errors because annotation processing haven't run to generate the required code. Lets assume you see 10 compile errors in Android Studio when pressing the green play button to compile and run your app, but the real problem is the single compile error mentioned before. So you have to check the list of 10 compile errors manually and simply ignore the errors caused by annotation processing and find and fix the single one compile error. So it's not necessary to uncomment everything related to sqlbrite-dao. You only have to detect and fix the single compile error who causes the whole mess (and list of errors). Showing the imports as missing seems to be android studio bug. I have also seen this kind of issue with dagger 2 (missing imports). Deleting all .idea files and folders and reimporting the whole app project in Android Studio solved the "imports" issue most of the time.

I'm afraid but I think that I can't fix that.

harinair commented 8 years ago

Hannes... You did not understand my problem (again I am not a novice :-)). The errors you explained is common, I encountered them numerous times with Dagger and with your library, and can be solved. That would have been Ok. This is very different and weird: Here the SQLBrite and the sqlbrite-dao classes are not getting added to classpath. Now since the SQLBrite and the sqlbrite-dao are not in the classpath, I cannot fix errors. It will say method query() not found in DAO since the parent class "Dao" itself is missing - I won't even know which all are real errors and which all are errors since Dao is missing from the classpath.

sockeqwe commented 8 years ago

I do understand your problem. I'm having the same problem with Dagger2 @Module or @Component annotation from time to time. They also don't seem to be on the build path and hence I get a ton of errors saying @Module is unknown. But once I figure out what the real compile error is everything compiles again. To detect that I simply ignore all dagger related errors because I know dagger is not the real error cause.

You problem is basically the same, but yes you might have compile errors in your DAO as well which will be hard to fix without code completion and IDE support (since Android Studio says Dao is not in your build path). I do understand that. I can imagine that this is very painful to fix.

All I wanted to say is that from my point of view this is the same kind of issue you will face also with other annotation processing based libraries like dagger and it will also occur if one day you have to migrate from dagger 2.0 to dagger 2.1. With dagger it might be easier, because there is no dagger class you extend from (like Dao) so you don't have compile error in there.

But you might have compile errors in your @Module annotated MyModule class. In worst case you have to fix the compile errors from your MyModule without IDE auto completion support (similar to your problem).

Once again, I just wanted to point out that in my oppinion this is not a problem of sqlbrite-dao library, it can basically happen to other libraries like dagger as well.

Honestly, I don't know how to fix that. If you have any idea please let me know. From my point of view it's an error caused by Android Studio in combination with android's gradle plugin. I think that the android team have to fix that somehow. I will check their issue tracker if there is already such a issue reported.