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. Dismiss Notice

Question IPostGenerateGradleAndroidProject keeping old changes?

Discussion in 'Android' started by LesBloom, Apr 11, 2023.

  1. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    Hello,

    I am trying to use IPostGenerateGradleAndroidProject to add some data to my Android manifest file.

    My understanding is that the manifest file is fully generated during the build step, and that is why I need to use the IPostGenerateGradleAndroidProject system to inject my own custom values into it.

    I have been working on this, and, at various points, added the wrong values while testing / developing.

    However, those values don't disappear with each new build.

    I event disabled all of my code, and the various old, bad values are in the Android manifest file.

    I am really confused, because I thought this file was being fully generated with each build.

    Any help would be really apprecaited
    Thanks
     
  2. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    To better describe my problem, this is the data I am talking about

    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.  
    4.     // added in my 1st pass, was the wrong format
    5.     <package android:name="test" />
    6.  
    7.     // added in my 2nd pass, but then expanded in the 4th and 5th passes somehow
    8.     <queries>
    9.         <package android:name="test" />
    10.         <package android:name="test" />
    11.     </queries>
    12.     // added in my 3rd pass
    13.     <queries>
    14.         <package android:name="test" />
    15.     </queries>
    16.  
    17. </manifest>
    I am no longer running any of my code, but all those previous values are still there.

    I can manually edit the manifest file (even delete it), rebuild my app, and those values are in there again
     
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    It's because Android build pipeline became incremental in Unity 2021.2, and Unity only rebuild items when their dependencies change. While IPostGenerateGradleAndroidProject is called every time you click build. In the future this callback will be deprecated in favor of Android Configuration Manager - https://docs.unity3d.com/2023.1/Documentation/Manual/android-modify-gradle-project-files-agp.html which is incremental friendly.

    If you're not using 2023.1 or higher, you have several options:
    * Use https://docs.unity3d.com/ScriptReference/BuildOptions.CleanBuildCache.html if you're building via API, the downside you'll be producing your build from scratch every time
    * if you're building via UI, there's a dropdown button Clean, which will clean the build before producing it.
    * Make your code smarter in IPostGenerateGradleAndroidProject and be able to both add and remove values depending on the logic you need

    Hope that helps a bit.
     
  4. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    Thank you, @Tomas1856

    I really appreciate that info. It helps a lot to understand what is going on here.

    I will dig into those various options to figure out my solution.

    Cheers