Other [new feature] Three birds with one stone

Discussion in 'Android Questions' started by Erel, Feb 4, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    B4A v5.80 includes a new attribute named #ExcludeClasses.

    Example:
    Code:
    #ExcludeClasses: com.google.ads, anywheresoftware.b4a.phone.RingtoneManager
    During compilation, all classes from all referenced libraries, that their full name (package + class) starts with one of the above prefixes, will not be included in the APK.

    Why is it useful?
    1. Smaller APK, faster compilation and faster installation. This is especially useful when referencing the large google play services library.
    2. Removing libraries based on the selected build configuration. Like all other attributes you can use compilation symbols to add or remove this attribute.
    3. Removing unsupported classes. For example, Amazon rejects APKs that include the RingtoneManager classes. So instead of modifying the Phone library, you can exclude the problematic classes.
    As google play services is the main candidate for this feature, any prefix that starts with a dot will be converted to google play services package (com.google.android.gms).

    If you are only interested in the maps functionality of google play services:
    Code:
    #ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
    #ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .vision, .gcm
     
    Last edited: Feb 23, 2016
  2. ArminKH

    ArminKH Well-Known Member

    isn't it better if unused classes removed automatically by compiler? like a future which is exist in b4a named Clean Project ?
    i know maybe this is headache(or not for u) when compiler need to looking for relations between classes and need it's own strategy,but u can have this in your mind as a wish for the next version of the next version.
    any way this is really great future at all and thank u.
     
    fireday, erfanmola and Cableguy like this.
  3. DonManfred

    DonManfred Expert Licensed User

    Do you know an ETA for the new B4A Version? Asking about the new CustomProperties for CusomViews-Feature in next B4A Version :D
     
    ArminKH likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    This feature allows you to strip out classes from the referenced jars not from your project. The compiler cannot know which classes are not required.

    The beta version will be released in a week or two.
     
    giga, DonManfred and ArminKH like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    Another important new feature:

    CreateResource command in the manifest editor.

    Code:
    SetApplicationAttribute("android:theme""@style/AppTheme")
    CreateResource(values, theme.xml,
    <resources>
      <style name=
    "AppTheme" parent="android:Theme.Material.Light">
      <item name=
    "android:colorPrimary">#FFEAC80E</item>
      <item name=
    "android:colorPrimaryDark">#FFEA0ED7</item>
      <item name=
    "android:colorAccent">#FFF8F8F8</item>
      </style>
    </resources>
    )
    CreateResource creates an XML resource file. In the above example a file named theme.xml will be created under res\values.

    This makes it easier to customize the themes, all from the manifest editor.
    Remember that the manifest editor supports conditional compilation. So it is also possible to change the resources based on the selected build.
     
  6. LucaMs

    LucaMs Expert Licensed User

    I suppose you are sure about this. The compiler knows if a routine of a my class module is unused: cannot it "explore" the jar, search for unused public routines in the project and exclude them?

    [I also suppose, the answer: "No" :)]
     
    ArminKH likes this.
  7. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Seems to be very costly since we can do it by hand

    Edit: sorry, what I mean is : the compiler should do this each compilation time // we do it one time when we create the app and can change it after to adapt
     
    ArminKH and LucaMs like this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    The full answer is that the compiler can strip unused classes but not without mistakes. With mistakes I mean that it will remove required classes. Think about the usage of reflection inside a library (and there are such usages). A static analyzer will not be able to know which classes are used.

    For further discussions about this topic, please start a new thread.
     
  9. LucaMs

    LucaMs Expert Licensed User

    I know, but we will spend more time than the compiler and we could make mistakes.
    If necessary, we could choose an "exclusionary compilation" only for the final release
     
    ArminKH and lemonisdead like this.
  10. LucaMs

    LucaMs Expert Licensed User

    To understand this answer I need more time, and I'm running :)

    Thank you
     
    lemonisdead and ArminKH like this.
  11. sorex

    sorex Expert Licensed User

    Excellent! I've been waiting for this for decades with other compilers that added too much unused stuff.
     
    lemonisdead likes this.
  12. LucaMs

    LucaMs Expert Licensed User

    I got it ;)
     
    lemonisdead likes this.
  13. Robert Valentino

    Robert Valentino Active Member Licensed User

    Will the new version offer SPACES instead of TABS?

    BobVal
     
  14. Informatix

    Informatix Expert Licensed User

    I will continue to use ProGuard as it shrinks my APK automatically, but it's a great feature anyway. The new version is more and more attractive.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    It is better to start a new thread for such questions. The answer is no.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Example of using CreateResource to set the native light theme on Android 4+:
    Code:
    SetApplicationAttribute(android:theme, "@style/LightTheme")
    CreateResource(values-v20, theme.xml,
    <resources>
      <style
      name=
    "LightTheme" parent="@android:style/Theme.Material.Light">
      </style>
    </resources>
    )
    CreateResource(values-v14, theme.xml,
    <resources>
      <style
      name=
    "LightTheme" parent="@android:style/Theme.Holo.Light">
      </style>
    </resources>
    )
     
  17. ArminKH

    ArminKH Well-Known Member

    also can be used for animation xml files?
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    Yes, it can be used to create any text based resource file.
     
  19. Guardian17

    Guardian17 Active Member Licensed User

    For #ExcludeClasses, does there exist some list of all classes that can be excluded, so that I can examine the list and then determine what I can Exclude?
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    You can always open the jar file with a tool such as 7zip and see all the classes and packages.

    Specific to google plays services then the list I posted in the first post covers all the non-small packages. The only one missing is .maps.
     
    koaunglay likes this.
Loading...