Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory not generated sometimes #58

Closed
PaulWoitaschek opened this issue Feb 9, 2018 · 24 comments · Fixed by #63
Closed

Factory not generated sometimes #58

PaulWoitaschek opened this issue Feb 9, 2018 · 24 comments · Fixed by #63

Comments

@PaulWoitaschek
Copy link

When running my app which uses kotshi in a module from android studio, everything is fine.
However when I run it from commandline in tests, it fails because the adapter factory is not generated.

I made a sample probject:
https://github.com/PaulWoitaschek/KotshiFactoryBug

which fails when running ./gradlew test

@PaulWoitaschek
Copy link
Author

Actually it's strange. When just cloning the repo and running the test from command line, everything works fine. But if I then compile and launch the app using Android Studio and then call ./gradlew test and then launch it using Android Studio again, it fails.

@ansman
Copy link
Owner

ansman commented Feb 9, 2018

It works just fine for me, weird.

@PaulWoitaschek
Copy link
Author

PaulWoitaschek commented Feb 9, 2018

These steps fail 100% of the time for me.

  1. Git Clone
  2. Add it in android studio
  3. Press run
  4. Run ./gradlew test in the terminal tab

@ansman
Copy link
Owner

ansman commented Feb 9, 2018

It seems to be an issue regarding KAPT, if I clean and build again it works just fine.

@PaulWoitaschek
Copy link
Author

Do you have any idea what is going on there? I can't find other words for reporting it upstream other than "not working sometimes" ;)

@PaulWoitaschek
Copy link
Author

I ask myself why that whole ceremony is necessary at all.

I mean by looking at FactoryProcessingStep.kt it seems like there can be only a single factory at all. So why not just generate a factory?

It feels strange to create a class, annotate it with something and then let that class extend something that is based upon the fact that it is annotated. That's a circular chain.

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 9, 2018 via email

@vincent-paing
Copy link

vincent-paing commented Feb 14, 2018

Having same problem. Running the app is fine but running unit test or UI test will cause the factory not to be generated. I got this error in my terminal

e: /Users/vincent/AndroidStudioProjects/{Project NAME}/data/build/tmp/kapt3/stubs/debug/mm/pulse/prices/data/network/AppJsonAdapterFactory.java:10: error: cannot find symbol
public final class AppJsonAdapterFactory extends mm.pulse.prices.data.network.KotshiAppJsonAdapterFactory {
                                                                                     ^
  symbol:   class KotshAppJsonAdapterFactory
  location: package mm.pulse.prices.data.network

FAILURE: Build failed with an exception.

@ansman
Copy link
Owner

ansman commented Feb 14, 2018

Could you check the following things for me:

  1. Is the factory actually generated (if you look in the build folder)?
  2. Does the same issue happen with 0.3.0?

@vincent-paing
Copy link

vincent-paing commented Feb 14, 2018

It seems like the factory is not generated under build folder, the jsonadpater each object is created tho.

EDIT: Seems to be working fine with 0.3.0. I'll be sticking to it for a while

@ansman
Copy link
Owner

ansman commented Feb 14, 2018

I wonder if it has to do with the fact that you subclass something that doesn't exist. But it should still run the code.

@PaulWoitaschek
Copy link
Author

Btw the generation of the adapters is completely reliable.

As a workaround I just copied the generated factory and manually add new adapters by hand.

@vincent-paing Do you also have the kotshi stuff in a library module?

@vincent-paing
Copy link

Yes, I'm having kotshi stuffs in my library module(data module as in the path). Trying to build an app with clean architecture so I'm separating it from my actual app module.

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 14, 2018 via email

@ansman
Copy link
Owner

ansman commented Feb 14, 2018

Hmm, ok. So this seems to be a universal problem them, we could just revert to the previous way of implementing the factory but I would want to understand why it's happening. It feels like a bug in kapt and not Kotshi.

@ansman
Copy link
Owner

ansman commented Feb 14, 2018

I wonder if it's because of the bump to Kotlin 1.2.21, only thing I can think of that might cause this.

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 14, 2018 via email

@ansman
Copy link
Owner

ansman commented Feb 14, 2018

Hmm, ok. Well I don't really know what could cause this: 0.3.0...1.0.0

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 14, 2018 via email

@ansman
Copy link
Owner

ansman commented Feb 15, 2018

I'll add a PR that allows both the new and old way of implementing the factory. Let's see if that helps.

@ansman
Copy link
Owner

ansman commented Feb 16, 2018

Please try the snapshot 1.1.0-20180215.183751-6, with that you can use the old way of implementing the factory:

@KotshiJsonAdapterFactory
abstract class MyFactory : JsonAdapter.Factory {
  companion object {
    @JvmField
    val INSTANCE: MyFactory = KotshiMyFactory()
  }
}

Let me know if the problem persists.

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 16, 2018 via email

@ansman
Copy link
Owner

ansman commented Feb 20, 2018

Ok, I've implemented so that the pre 1.0 way is allowed too. I'll try to file an issue on youtrack and fix the root issue.

@ansman ansman closed this as completed Feb 20, 2018
@ansman
Copy link
Owner

ansman commented Apr 28, 2020

FYI, the issue has been fixed in the latest version of Kotshi and the preferred way to declare you factory is as an object that subclasses the generated factory

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

Successfully merging a pull request may close this issue.

4 participants