stephanenicolas / toothpick

A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.
Apache License 2.0
1.12k stars 115 forks source link

Toothpick with Android's jack compiler #198

Closed radekkozak closed 7 years ago

radekkozak commented 7 years ago

Since i cannot find any information on this: does Toothpick suppose to work with Android's jack compiler ?

Trying to steer from from Dagger2 to Toothpick but i'm getting weird results generated from annotation processor when using following gradle config:

android {
...

       jackOptions {
            enabled true
        }
}

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
}

Example:

public final class MainActivity$$Factory implements Factory<MainActivity> {
  private MemberInjector<MainActivity> memberInjector = new package com.radekkozak.android.toothpicksample.MainActivity$$MemberInjector();

 ...
}

Problem is the "package" keyword somehow (have no idea from where) getting in between thus generating following errors

ToothpickSample/app/build/generated/source/apt/debug/package com/radekkozak/android/toothpicksample/MainActivity$$Factory.java:8.61: MainActivity cannot be resolved to a type

and

_ToothpickSample/app/build/generated/source/apt/debug/package com/radekkozak/android/toothpicksample/MainActivity$$Factory.java:9.61: Syntax error on token "package", delete this tok_en

Problem seems to go away simply by disabling jack compiler and reverting back to JavaVersion.VERSION_1_7

Problem shows with Toothpick's reflection either turned on or off

Toothpick.setConfiguration(Configuration.forProduction().disableReflection());
MemberInjectorRegistryLocator.setRootRegistry(new com.radekkozak.android.toothpicksample.MemberInjectorRegistry());
FactoryRegistryLocator.setRootRegistry(new com.radekkozak.android.toothpicksample.FactoryRegistry());
stephanenicolas commented 7 years ago

And you didn't have this issue with dagger 2 ?

2017-02-10 11:02 GMT-08:00 Radek Kozak notifications@github.com:

Since i cannot find any information on this: does Toothpick suppose to work with Android's jack compiler ?

Trying to steer from from Dagger2 to Toothpick but i'm getting weird results generated from annotation processor when using following gradle config:

android { ...

   jackOptions {
        enabled true
    }

}

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

Example:

public final class MainActivity$$Factory implements Factory { private MemberInjector memberInjector = new package com.radekkozak.android.toothpicksample.MainActivity$$MemberInjector();

... }

Problem is the "package" keyword somehow (have no idea from where) getting in between thus generating following errors

ToothpickSample/app/build/generated/source/apt/debug/package com/radekkozak/android/toothpicksample/MainActivity$$Factory.java:8.61: MainActivity cannot be resolved to a type

and

_ToothpickSample/app/build/generated/source/apt/debug/package com/radekkozak/android/toothpicksample/MainActivity$$Factory.java:9.61: Syntax error on token "package", delete this tok_en

Problem seems to go away simply by disabling jack compiler and reverting back to JavaVersion.VERSION_1_7

Problem shows with Toothpick's reflection either turned on or off

    Toothpick.setConfiguration(Configuration.forProduction().disableReflection());
    MemberInjectorRegistryLocator.setRootRegistry(new com.radekkozak.android.toothpicksample.MemberInjectorRegistry());
    FactoryRegistryLocator.setRootRegistry(new com.radekkozak.android.toothpicksample.FactoryRegistry());

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stephanenicolas/toothpick/issues/198, or mute the thread https://github.com/notifications/unsubscribe-auth/ABv33STzuowdkHAtzqSzZq3DsIIR-Rl7ks5rbLQ6gaJpZM4L9vB3 .

radekkozak commented 7 years ago

Hi, no - not really. Bunch of others though but all is working ok with 2.9 version of dagger.

I'm just trying to get my hands Toothpick to see how it would fit, but that what i mentioned came up which seems weird. The "package" word from generated factory doesn't seem to be there with java 1.7 and jack turned off.

Problem is (obviously) with instantiation as syntax is of course not right here. Just to be safe i manually deleted "package" token from the first line in that factory and all goes away. But of course after it is generated again it comes back (duh)

Any idea what's causing that extra "package" word in between there ? Should i just simply revert to retrolambda with 1.7. What's your guess ?

Thanks in advance

stephanenicolas commented 7 years ago

No real idea on this. Can you setup a github project or a PR failing on compilation that we can start investigating?

Thx ! We heard so many comments about Jack and Jill (JJ) being immature yet that we didn't even try it yet.

But you right this is definitely a bug. I would say in JJ but we need to double check and file a detailed bug report if so.

Le ven. 10 févr. 2017 14:12, Radek Kozak notifications@github.com a écrit :

Hi, no - not really. Bunch of others though but all is working ok with 2.9 version of dagger.

I'm just trying to get my hands Toothpick to see how it would fit, but that what i mentioned came up which seems weird. The "package" word from generated factory doesn't seem to be there with java 1.7 and jack turned off.

Problem is (obviosuly) with instantiation as syntax is of course not right here. Just to be safe i manually deleteg "package" token from the first line in that factory and all goes away. But of course after it is generated again it comes back (duh)

Any idea what's causing that extra "package" word in between there ? Should i just simply revert to retrolambda with 1.7. What's your guess ?

Thanks in advance

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stephanenicolas/toothpick/issues/198#issuecomment-279080728, or mute the thread https://github.com/notifications/unsubscribe-auth/ABv33ZSsQkgiHbcdkp6hI0SeYBMp0if-ks5rbODigaJpZM4L9vB3 .

radekkozak commented 7 years ago

Yup heard that too about JJ but thankfully so far i had mild problems that were easy to conquer. This thing with Toothpick seems to be rather trivial to repair but like you i'm sensing it is sth to do with jack (concretely transformJackWithJackForDebug task i think) as your FactoryGenerator code seem to be ok. Feel free to investigate on your own though, you know your code better of course.

Anyway i got your sample ready and FAILING as issue-198 branch in my fork so i can PR. Should i do it to your base master or would you prefer to prepare similar branch on your side first ?

Let me know

stephanenicolas commented 7 years ago

Jack is dead: https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html