Giter Site home page Giter Site logo

Comments (6)

mgsx-dev avatar mgsx-dev commented on June 1, 2024 4

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.

tommyettinger avatar tommyettinger commented on June 1, 2024 3

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.

obigu avatar obigu commented on June 1, 2024 3

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.

b3nk4n avatar b3nk4n commented on June 1, 2024 3

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.

Frosty-J avatar Frosty-J commented on June 1, 2024 2

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.

tommyettinger avatar tommyettinger commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.