Closed LukasWillin closed 5 years ago
I don't understand what you are trying to do: the service class is the one configuring the scope, but you use it from the activity. Is the scope configured, with all modules installed when you do Toothpick.inject(this, Toothpick.openScope(FeedbackSingleton.class));
?
Also, it is quite strange to have a binding pointing to this and injecting this via DI. But I assumed it was for the sake of your example.
Yeah I thought this Question might come.
So the FeedbackSetupService acts as the entry point to the library and needs to do some initialization. Therefor he needs to get hold of the injected instances. So he also acts as the exit point seen from the library itself. But he hides behind the interface IFeedbackExitPoint.
The Open Method of the FeedbackSetupService can be called from outside eg whoever will using the library. So open(someActivity)
will be called before Toothpick.inject(this, Toothpick.openScope(FeedbackSingleton.class))
.
We made this decision so we can free memory while the library is not in use. But yes it probably looks quiet strange and is surely not ideal.
To answer the second question: All modules required should be installed once it reaches the first Activity. At least when running it through Android Studio everything runs as expected. Installing and running a signed APK however crashes with given exception.
EDIT: Now I know what you mean exactly. Yeah that first injection of this (FeedbackSetupService) into itself was merely for testing purposes and to show the strange behaviour. Thats definitely NOT in there normaly.
If it works when running in debug mode, and not in release mode, your problem probably comes from obfuscation. Then you would have a different stack trace too, not one starting as an issue from the activity..Do you obfuscate your apk and if so did you configure it to preserve TP classes and generated code? See the wiki on how to do it.
You can also dump a scope using toString and see what are the bindings available. It can help debug.
I will look into it thank you for your hints!
Feel free to re-open, but the problem doesn't seem to come from TP.
Hi Nicolas
I disabled everything from obfuscation and minification. But it still wont work. It also doesnt matter if I build it as signed debug or release. It only works if I directly run it through Android Studio.
I probably doing some beginner mistake but I really cant figure it out.
I also changed the TP-configuration from development to production and removed the @Inject IFeedbackExitPoint
for the Activity. But it now wont find other module instances.
Is there something special I need to look out for when using it inside of a library? Do you have any other ideas?
Send us the exact stack trace. Please look into your apk (you can use Android Studio, or command line tools) to check if you got the __Factory/MemberInjector classes that appear to be missing according to the stack trace. If they are not present, check inside the build folder of your app.
Le mer. 7 août 2019 à 12:48, Lukas Willin notifications@github.com a écrit :
Hi Nicolas
I disabled everything from obfuscation and minification. But it still wont work. It also doesnt matter if I build it as signed debug or release. It only works if I directly run it through Android Studio.
I probably doing some beginner mistake but I really cant figure it out. I also changed the TP-configuration from development to production and removed the @Inject IFeedbackExitPoint for the Activity. But it now wont find other module instances.
Is there something special I need to look out for when using it inside of a library? Do you have any other ideas?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/stephanenicolas/toothpick/issues/356?email_source=notifications&email_token=AAN7PXJBA3TZGN2T3CQ3IQDQDMRJFA5CNFSM4IJ65NLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3ZQO2Q#issuecomment-519243626, or mute the thread https://github.com/notifications/unsubscribe-auth/AAN7PXOFEQOFTNHE672P7K3QDMRJFANCNFSM4IJ65NLA .
Thank you for your help! I am incredibly humbled. I check that again. Yesterday the MemberInjectors were there (at least what i can recall from memory) but I might have missed something. I'll repost once I know more.
Okay so I checked and some things seem to be missing but also not... if that makes any sense...
So TP complains it cant find the Factory for the AssetsService. However we got a provider for that which we also inject. However I dont see why this would suddenly fail. It works for the direct run from Android Studio (both Release and Debug Build Types) why would it suddenly not use the Provider for the AssetsService when building and installing a signed APK?
AssetsServiceProvider
public class AssetsServiceProvider implements Provider<AssetsService> {
@Inject
Application application;
public AssetsServiceProvider() {
Toothpick.inject(this, Toothpick.openScope(FeedbackSingleton.class));
}
@Override
public AssetsService get() {
return new AssetsService(application);
}
}
Injection of AssetsServiceProvider
feedbackScope.installModules(new Module() {{
bind(FeedbackRoomDatabase.class).toProviderInstance(new FeedbackRoomDatabaseProvider());
final AssetsServiceProvider assetsServiceProviderInstance = new AssetsServiceProvider();
bind(AssetsServiceProvider.class).toInstance(assetsServiceProviderInstance);
bind(AssetsService.class).toProviderInstance(assetsServiceProviderInstance);
bind(FileService.class).toProviderInstance(new FileServiceProvider());
}});
2019-08-08 15:58:27.377 25139-25139/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: ch.fhnw.edu.fcp.feedbackcommprocess, PID: 25139
java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.fhnw.edu.fcp.feedbackcommprocess/ch.fhnw.edu.fcp.postcard.activity.TextSideActivity}: toothpick.locators.NoFactoryFoundException: No factory could be found for class ch.fhnw.edu.fcp.postcard.configuration.assets.AssetsService. Check that the class has either a @Inject annotated constructor or contains @Inject annotated members.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2919)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: toothpick.locators.NoFactoryFoundException: No factory could be found for class ch.fhnw.edu.fcp.postcard.configuration.assets.AssetsService. Check that the class has either a @Inject annotated constructor or contains @Inject annotated members.
at toothpick.locators.FactoryLocator.getFactory(FactoryLocator.java:21)
at toothpick.ScopeImpl.lookupProvider(ScopeImpl.java:329)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:58)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:49)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__MemberInjector.inject(FeedbackConfigurationService__MemberInjector.java:11)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__MemberInjector.inject(FeedbackConfigurationService__MemberInjector.java:8)
at toothpick.InjectorImpl.inject(InjectorImpl.java:23)
at toothpick.Toothpick.inject(Toothpick.java:163)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService.<init>(FeedbackConfigurationService.java:26)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__Factory.createInstance(FeedbackConfigurationService__Factory.java:14)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__Factory.createInstance(FeedbackConfigurationService__Factory.java:8)
at toothpick.InternalProviderImpl.get(InternalProviderImpl.java:94)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:58)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:49)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity__MemberInjector.inject(TextSideActivity__MemberInjector.java:11)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity__MemberInjector.inject(TextSideActivity__MemberInjector.java:8)
at toothpick.InjectorImpl.inject(InjectorImpl.java:23)
at toothpick.Toothpick.inject(Toothpick.java:163)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity.onCreate(TextSideActivity.java:139)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: ch.fhnw.edu.fcp.postcard.configuration.assets.AssetsService__Factory
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at java.lang.Class.forName(Class.java:378)
at toothpick.locators.FactoryLocator.getFactory(FactoryLocator.java:18)
at toothpick.ScopeImpl.lookupProvider(ScopeImpl.java:329)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:58)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:49)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__MemberInjector.inject(FeedbackConfigurationService__MemberInjector.java:11)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__MemberInjector.inject(FeedbackConfigurationService__MemberInjector.java:8)
at toothpick.InjectorImpl.inject(InjectorImpl.java:23)
at toothpick.Toothpick.inject(Toothpick.java:163)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService.<init>(FeedbackConfigurationService.java:26)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__Factory.createInstance(FeedbackConfigurationService__Factory.java:14)
at ch.fhnw.edu.fcp.postcard.configuration.FeedbackConfigurationService__Factory.createInstance(FeedbackConfigurationService__Factory.java:8)
at toothpick.InternalProviderImpl.get(InternalProviderImpl.java:94)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:58)
at toothpick.ScopeImpl.getInstance(ScopeImpl.java:49)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity__MemberInjector.inject(TextSideActivity__MemberInjector.java:11)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity__MemberInjector.inject(TextSideActivity__MemberInjector.java:8)
at toothpick.InjectorImpl.inject(InjectorImpl.java:23)
at toothpick.Toothpick.inject(Toothpick.java:163)
at ch.fhnw.edu.fcp.postcard.activity.TextSideActivity.onCreate(TextSideActivity.java:139)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-08-08 15:58:27.377 25139-25139/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "ch.fhnw.edu.fcp.postcard.configuration.assets.AssetsService__Factory" on path: DexPathList[[zip file "/mnt/expand/0c815ad2-6acf-42db-ab64-6125c2e82827/app/ch.fhnw.edu.fcp.feedbackcommprocess-4Vv_NyaGf8YHxDDq-N_uDA==/base.apk"],nativeLibraryDirectories=[/mnt/expand/0c815ad2-6acf-42db-ab64-6125c2e82827/app/ch.fhnw.edu.fcp.feedbackcommprocess-4Vv_NyaGf8YHxDDq-N_uDA==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 37 more
The scope you are using is not configured. Are you sure your code goes into the open method ? Can you log something there ? Also, log the scope object ID (using System.hascode) both when you configure and use the scope. They might be different instances. You can't debug bug you can use Log.d/e
.
When you openScopes, you have to make sure that the first time they will be opened starting from the root scope: openScopes(application, Annotation.class)
so that you indicate that each scope has a parent in the scope tree.
Ill try that one! I am sure it goes into the open method because I am already logging the version there :/ So that is sadly out of the question.
However I might have found another issue which also contributes to it. I will have to have another look.
Hi Nicolas
Thank for all your support. I got it working. The build never had an issue but rather the phone I tested on. I shouldve known better...
I am sry for occupying your time for something so trivial. If there is anything I can help you with no matter how simple the work please feel free to contact me. That is the least I can do to give smth back to this project.
Regards Lukas
Thx for your kind words. Good luck with your app, and feel free to consider switching to TP 3! It just got released.
Already did ;) Thank you!
Hi Together
I got an issue when building the apk and trying to run it.
I know others had such problems as well but none of those issues sadly seem to apply to me. :/
I am creating an Android Library and so far everything worked fine when running it through Android Studio in a demo app. However once I create the signed APK some things seem to go a bit awry. Suddenly Toothpick complains that it cannot locate certain Member Injectors. Even though I am binding & injecting the instances myself.
Am I missing something during the build phase which I need to change?
Information
I am sry I know its a lot. But I think something in here is contributing to the issue but I cant figure out what it is.
Here I am binding all required instances to the Scope
FeedbackSingleton.class
This activity fails to inject suddenly in the signed APK.
Information about IFeedbackExitPoint
IFeedbackExitPoint#close takes care of closing the TP scope as well as making sure to tear down any other ressources used.
This is the stacktrace which I am suddenly getting in the singed APK.
Using gradle directly lint complains as well
App Gradle (Demo App)
Library Module Gradle (Feedback)