Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Size problem when using Unity as library in a Native Android App

Discussion in 'Android' started by mickfcna, Nov 29, 2021.

  1. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hello everybody,

    First of all thank you to all who read me and for your answers. I'm using Unity 2019.4 LTS using the IL2CPP scripting back end for Android. I'm trying to create a SDK using Unity as a library in a Native Android app. When I export the UnityLibrary for Android (ARM64 only) the size of my AAR is 17Mo.

    All is working fine, my sdk.aar is only 167ko but when I build an apk on my own app with this sdk it turns 60Mo (in an empty project) How is it possible ?
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,682
    I assume your SDK doesn't include Unity player files, so that would be the reason why it's so small. But apk will include Unity player files, that would be the reason it will grow.

    In any case, to now for sure, simply unzip aar or apk and check the file inside
     
    mickfcna likes this.
  3. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hello Tomas,

    Thank you so much for your help.
    When I unzip, those 2 libs are very big, our customers complain about the size of the apk with our integrated SDK.

    With our SDK the APK of our customer is x4 bigger and that penalizes them in the Playstore and Appstore.

    Is there a way to reduce the size?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,682
    In Player Settings:
    * Try setting C++ Compiler Configuration to Master
    * Check that Strip Engine Code is On
    * Try setting Managed Stripping Level to High.
    * From Unity project go to Package Manager, or open Packages/manifest.json and remove the packages you don't require.

    Hope that helps
     
    mickfcna likes this.
  5. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hello Tomas,

    Thank you for your help.

    I tried your tips, and it has an impact in the export aar decreasing the size from 17Mo to 15Mo, but didn't change the apk size (60Mo). We managed to go from 60MB to 28MB using the aab but we can't deploy it outside the playstore.

    Do you have another tips to decrease the apk and why it's two less bigger using aab ?

    Thanks,
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,682
    Not sure, try creating apk from aab using bundletool, and see what the final apk will be. Since you cannot compare aab vs apk directly
     
    mickfcna likes this.
  7. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hello Tomas,

    Thank you for your help again. It seemed like a good idea, I tried and it created 85 apks, the two biggest APK seems to be the same (see image below). I tried to install the first one and the second one but it didn't work on my smartphone.

    Do you have an idea why it creates so many apks and some in double ?

    Thx

    upload_2021-12-2_14-21-51.png
     
  8. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hello,

    I searched on Internet why it creates so many apk and somes in double, didn't find anything. Is it an unity bug ?

    Thanks for helping,
    Regards,
     
  9. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,682
    I think bundletool creates all possible variations of apk, it doesn't mean that all of them will be used.

    What command line did you use for bundletool? if I am not mistaken you can use --device-id to instruct bundle-tool to build apk specifically for your device, that might make it easier for you to produce a correct one.

    Alternatively, I think you can even specify manual configuration like shown here - https://developer.android.com/studio/command-line/bundletool#manually_create_json
     
  10. Sakshi_09

    Sakshi_09

    Joined:
    Jul 3, 2020
    Posts:
    8
    Hi,
    i am having same problem when using unity as a library in my native application, the size of apk is increasing around 37-45mb.
    Did you find any solution for this? Please Help.

    Thanks
    Sakshi
     
  11. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Sorry, still have the same issue...