Search Unity

[User Proguard File] option with Cloud Build

Discussion in 'Unity Build Automation' started by kyou_unity, Jun 11, 2019.

  1. kyou_unity

    kyou_unity

    Joined:
    May 7, 2019
    Posts:
    4
    Hello,
    I have a question about User Proguard File option when I try to build a Unity project for Android.
    When I start build from Unity > File > BuildSetting > Build with

    upload_2019-6-11_15-53-38.png
    It works fine.
    But when I try to build from BuildPipeline/Cloud Build I found that I can't set for Use Proguard File.
    There is a way to set BuildSystem and Minify by

    EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
    EditorUserBuildSettings.androidReleaseMinification = AndroidMinification.Proguard;

    but it seems not enough and cause a build error.
    This opitions are not saved by any settings.asset either.

    How can I build from BuildPipeline or Cloud Build with my own proguard file?

    Thank you
     
    BilalShahid and TheChosenBlob like this.
  2. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
  3. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
    Supposedly this box gets ticked automatically if you have the proguard-user.txt file in the default path (Assets/Plugins/Android/). That seems to be working for us.
     
  4. kyou_unity

    kyou_unity

    Joined:
    May 7, 2019
    Posts:
    4
    Yes, just as you said,「Custom Gradle Template」and 「User Proguard File」will be on automatically when Unity detected mainTemplate.gradle and proguard-user.txt file
     
  5. TheTaj

    TheTaj

    Joined:
    Jun 26, 2014
    Posts:
    24
    Just commenting here in case anyone else comes across this issue and is mislead by this inaccurate information:
    The presence of the mainTemplate.gradle and proguard-user.txt file *do not* necessitate that the Unity Cloud build will turn proguard on when building. In testing this theory, none of my files were obfuscated.
    It is very likely the solution to having proguard enabled on Unity Cloud Builds involves generating a mainTemplate.gradle file and adding lines to specify this setting as mentioned here: https://forum.unity.com/threads/using-gradle-build-system-with-cloud-build.453952/
    I will confirm if I can get a Cloud-Built .apk that has obfuscated files.

    Edit/Update:
    Things may be different for different unity versions, but for me (2019.4.4) I was able to fix this issue by renaming my proguard-user.txt file to proguard-android
    Then Player Settings > Publishing Settings > Generate custom gradleLauncher
    adding true/false to the 'useMinifier' and 'useProguard' lines in the generated file

    Code (CSharp):
    1. buildTypes {
    2.         debug {
    3.             minifyEnabled false
    4.             useProguard false
    5.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    6.             jniDebuggable true
    7.         }
    8.         release {
    9.             minifyEnabled true
    10.             useProguard true
    11.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
    12.         }
     
    Last edited: Oct 14, 2020
    ilmario and guneyozsan like this.
  6. guneyozsan

    guneyozsan

    Joined:
    Feb 1, 2012
    Posts:
    99
    I can confirm this worked for Unity 2018.4.27f1. I was able to build using cloud build and get rid of a related warning on new Play Console:
    "This App Bundle contains Java/Kotlin code, which might be obfuscated. We recommend you upload a deobfuscation file to make your crashes and ANRs easier to analyze and debug."