Sserra90 / Bulldog

Android library to simplify reading and writing to SharedPreferences, never write code like this anymore prefs.edit().putString("someKey","someString").apply()
126 stars 9 forks source link

Make Android Studio recognize the generated class #2

Open codeniko opened 5 years ago

codeniko commented 5 years ago

This is great work and is very simple to use. There could be improvements with that android studio doesn't seem to recognize the generated class even after building. It always says Unresolved reference. Fixing this allows for auto completion and removes all the red text where android studio yells at you because it thinks your code is wrong at every place you use one of the generated classes.

sergioserra commented 5 years ago

But can you use it ? Can you see to the generated classes ? Is just a matter of wrong imports in Android studio ?

codeniko commented 5 years ago

I believe I can definitely use it. I included it in my project first to test but I thought something was wrong because android studio kept showing unresolved reference. I figured it was broken. I then cloned this project and tried the demo app here. Same issue so I tried running the demo app anyway and it works fine, but android studio continues to show unresolved reference. I'm assuming if I ran it in my app instead of worrying that android studio couldn't find it, it would work too. I don't think being able to run is the point of this issue though, it's more the issue that android studio can't ever find the generated classes

I did some more exploring and here's what I found. Generated class seems to always be unresolved reference and you have to manually import it. Auto-complete import doesn't work. After manual import, the import itself shows unresolved reference as well. Seeing these errors, red markings and having no auto-complete is kind of annoying during development, especially on a library you're not yet familiar with.

The demo app has this same issue in android studio. As master is right now, look at MainActivity in android studio and you'll see android studio mark your code in red. You can then try creating a new package for UserSettings, like package com.criations.bulldog.whatever.UserModel. You then have to manually add the import in MainActivity and you'll still get unresolved reference for the import and where UserSettings is used.

If it matters, my android studio version is 3.3 Canary 3, built July 10, 2018.

sergioserra commented 5 years ago

Thanks for the detailed explanation, so the problem is generated code not recognized by Android Studio. I had that problem once but a clean and build soved it. I will take a closer look at it when I find some free time.

Thanks

Sserra90 commented 5 years ago

Hi sorry for the long delay. Please use this in gradle file so Android studio can see the generated classes.

main { res.srcDirs = ["${buildDir.absolutePath}/generated/source/kaptKotlin/"] }