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
No logging framework implementation when enabling proguard on Android #126
Comments
The problem is that tinylog cannot find
|
Yes I know this, thank you for the information. I was already playing arround with keepdirectories but I didn't try yet with keepnames. Will try it when I'm at home. Thank you for the info. |
@grill2010 Your are welcome! Please let me know if it works for you :-) |
Hmm, I'm not able to make it work. I think it should work but still I get the same error.
Nothing seems to be working, for now I do not have any more ideas. |
@grill2010 Can you provide a minimal example project that reproduces the issue? I will analyze the cause. |
Sure, will try to provide some example project tomorrow. |
Faster than expected, here is a standard Android example with tinylog. I have included the pro guard rules and the build.gradle has minifying enabled. Same error occurs in this project. |
I've analyzed the apk of my example project and I found out that when I build the project with proguard enabled the folder services in the META_INF/services directory is missing completely. APK compiled with proguard Any ideas why this happens? I didn't dig very much into the tinylog project yet so I have no clue yet why this happens. |
@grill2010 The only way, I found to keep the With these ProGuard rules, tinylog works well with your example project.
However, I don't like using the |
Okay I see, interesting. I was also looking around on the Internet and what I found is that there were a lot of problems with the META-INF/services directory in regard to include it in the build apk and it seems somehow the problem still persists. It is somehow related to proguard and not gradle. But of course using dontshrink option is not ideal like you said... Edit: The dontshrink removes unused resources and proguard thinks that these resource files are somehow not needed and simply removes them. Maybe because they are not referenced directly in the code but are accessed via the ClassLoader. There must be a way to tell proguard to not remove this files. Another way would be to create a direct pseudo reference somewhere in the code so that proguard does not remove them, but I've not tested it yet. |
I found a workaround to tell ProGuard to keep the service files: protected void onCreate(Bundle savedInstanceState) {
ServiceLoader.load(LoggingProvider.class);
ServiceLoader.load(Writer.class);
ServiceLoader.load(Policy.class);
super.onCreate(savedInstanceState);
Logger.error("Test output");
...
} ProGuard rules:
I plan to add these For tinylog 3, I'm experimenting with a builder concept for instantiation of logging providers, writers, and policies. Then, even no ProGuard rules nor any workaround will be required for tinylog. This will also solve #127. |
Awesome. Thank you very much. |
@grill2010 Could you test the attached JARs? They contain the workaround with the |
Sure I will test it when I have time and will let you know what are the results. |
@pmwmedia ##---------------Begin: tinylog ---------- if I set the debuggable option to true, then its working. |
@Kameswari Are you able to reproduce this issue by using the official example project https://github.com/pmwmedia/tinylog-android-example? |
@pmwmedia Your sample is working fine. Going through my code and analyzing where I did wrong. Will let you know after I figured out. Thanks |
@pmwmedia sorry for not getting back to you. I've forgotten to reply, shame on me. Your example was working fine and I'm also now using the newest version of tinylog in my applications with proguard and it works now without any workarounds. |
@grill2010 Thanks for the reply. I have used below properties and its working fine in debug version build. Also in release mode, if I set debuggable property as true, its working fine. writer = rolling file I have used same properties in Sample project and it worked fine in release mode too. |
@grill2010 @pmwmedia My mistake. I forgot that I am writing the logs only in debug mode. It's working fine. Thanks for your support. |
This closed issue has been locked automatically. However, please feel free to file a new issue. |
Hi, I'm using tinylog version 2.0.0 on Android and it worked great. However I recently released my new app and I found out that the log file never gets created. So I started to investigate the issue. What I found out is that as soon as I enable proguard on my release build I receive following output on the logcat when I log something
My tinylog.properties file looks like this
and it is located in my resources folder. Everything is working when I'm not enabling proguard. Are there some proguard rules which needs to be added when using tinylog with proguard?
Edit: seems that the ServiceLoader could not get anyResourses
returns an empty Enumeration when enabling proguard.
The text was updated successfully, but these errors were encountered: