Comments (6)
I think that minify/obfuscate by default is a bad idea :
- some third party libs requires introspection / JSON serialisation and such.
- Third party libs being open source there is no reason to obfuscate them anyway.
- Even some game specific packages shouldn't be obfuscated (game state that you want to load/save)
So i think the best solution would be to provide a proguard template (commented by default) that users could enabled if they think it's good for their game. This template could illustrate how to do it properly :
- only obfuscate game specific root package (eg. com.my.gdxgame.*)
- and an example of exclusion of a game specific sub package (eg. com.my.gdxgame.state.*)
(@tommyettinger i saw your comment right after posting mine, glad to see we're on the same page :-) )
from libgdx.
The setup app(s) could include some simple configuration for Android to use in the generated project, and it could match what mgsx-dev suggested about obfuscating the game code by default but not obfuscating things we know need reflection to work, like scene2d.ui Skin code. Commented and documented sections that show what it would look like to make R8 keep your reflection-dependent code the same, that would be great. I'm not sure that a large library like libGDX should have minimization skipped for all of it; certainly we want dead code elimination to run on libGDX when it is a dependency, and I'm not sure what stage of R8 that falls under. Any extra steps of obfuscation can certainly be skipped for open source libraries... Minimization might still cause trouble, but for large libraries it could really help the output size.
from libgdx.
I agree with @tommyettinger , R8 is much more than obfuscation and actually recommended by Google for all apps so I'm in favour of the approach of adding exclusion rules to the default instead of the opposite. 3rd party libraries should either embed the required Proguard rules in their .aar or be documented. I agree we can add some more commented blocks for Scene2D to avoid issues with Skins (or have them enabled by default and add a comment that they can be commented out if Skins not used).
from libgdx.
Thanks for your answers above already. I appreciate it!
I agree we can add some more commented blocks for Scene2D to avoid issues with Skins (or have them enabled by default and add a comment that they can be commented out if Skins not used).
I would be fine with that. And maybe a note in the Skin docs would not harm. My concern is mainly "first user experience". A beginner programmer might not really know about ProGuard. And honestly very likely also not care too much about an as small as possible. And I'm sure especially many beginner developers will only dev/test their apps in DEBUG mode, and then release it to the store. And in that scenario (which also happened to my yesterday because of laziness 😇 ) it might be frustrating to see the app crash in production. While it worked perfectly fine during development.
But anyways, I think you guys can judge that better.
from libgdx.
Classes commonly accessed via reflection in skins could do with being excluded in the ProGuard rules. This issue comes up relatively frequently in the Android channel on Discord.
At least now you've experienced the importance of testing with the release version. If your app has a large userbase, you may wish to utilise Google Play's test tracks, and release updates to production as a staged rollout to reduce the number of users who may experience a bad update before you catch it.
from libgdx.
Minimization should generally be enabled when doing an Android release, unless you actually want larger APK/AAB sizes and effortlessly-dissected apps. ProGuard/R8 is invariably going to require some configuration when doing that; that's part of Android app development. There's a way to include R8 configuration in a library so apps use that configuration when depending on the library, but that config only works for R8 at the moment, not desktop ProGuard. This R8 configuration, which goes in the META-INF/proguard
directory, could be added to libGDX or the Android backend part of it.
I would also be remiss if I didn't mention that gdx-liftoff has partly solved this already, and includes these lines in Android's proguard-rules.pro
:
# You will need the next three lines if you use scene2d for UI or gameplay
# If you don't use scene2d at all, you can remove or comment out the next line
-keep public class com.badlogic.gdx.scenes.scene2d.** { *; }
# You will need the next two lines if you use BitmapFont or any scene2d.ui text
-keep public class com.badlogic.gdx.graphics.g2d.BitmapFont { *; }
# You will probably need this line in most cases
-keep public class com.badlogic.gdx.graphics.Color { *; }
Any libraries you depend on may have their own needs for reflection and may need more classes to be kept as-is. It is really hard, if not outright impossible, to make a general-purpose ProGuard or R8 file that works at the project setup stage, since libraries can be (and often are) added after that stage. If more libraries start using the R8 META-INF configuration, that might help the problem, but I believe this feature was added last year and wasn't usable for much of that year (because Gradle 8 had so many incompatibilities that needed resolving, such as with AGP).
I'd advise against disabling R8 for all of libGDX, but you could do that, I guess. It wouldn't help with any other dependencies.
from libgdx.
Related Issues (20)
- Can't use Lambda in newly created libgdx project (Jdk ver. set to 1_8/17) in Android Studio HOT 2
- Can not get superdevmode in RELEASE mode for HTML5? HOT 2
- Error with build desktop version HOT 1
- Support for ISO Keyboards HOT 6
- Support for drawable in SelectBox HOT 4
- Use official metal sources HOT 1
- AndroidFragmentApplication dies onPause HOT 1
- Performance issues on Android when enabling config.useGL30 HOT 7
- GWT requests unnecessary microphone permission HOT 5
- Stage.drawDebug does not work in combination with GL3 due to ShapeRenderer shader not being compliant HOT 2
- AndroidPreferences.flush() has no way to enforce synchronous saving HOT 2
- If an animation starts on frame 1 or more, rather than frame 0, AnimationController doesn't animate it properly
- glReadPixels does not support offset parameter crucial to read pixels asynchronously HOT 2
- gdx and gdx.jnigen.loader causes split module issue over package com.badlogic.gdx.utils HOT 6
- GWT preloader doesn't use percent-encoding HOT 2
- performance: unnecessary window.makeCurrent() in LWJGL3 backend HOT 5
- Add arm64 capabilities to Info.plist.xml HOT 1
- Suggestion to modify code in Sprite.rotate() method in com.badlogic.gdx.graphics.g2d.Sprite package HOT 4
- None of the 3D test apps in ..\tests\gdx-tests\src\com\badlogic\gdx\tests\g3d are build or runnable
- FPS Cap at runtime HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libgdx.