Version: 2023.2
LanguageEnglish
  • C#

AndroidProjectFilesModifier

class in UnityEditor.Android


Implements interfaces:IOrderedCallback

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

An abstract class that contains methods to modify Android Gradle project files during the build process.

This abstract class contains two callback methods: Setup and OnModifyAndroidProjectFiles. Unity calls Setup before the build begins and this method sets prerequisites for the build system. Unity calls OnModifyAndroidProjectFiles after it creates the Gradle project, which means all modifications you make in this method are applied directly to that project.

The generated files use Groovy syntax and all string-type properties use double quotes.

If your OnModifyAndroidProjectFiles callback depends on other files in the project (or on the local machine), or if you want the callback to produce new files, you must give this information to the build system in advance using Setup. The incremental build pipeline requires this information to know what files this callback produces and which files the callback depends on. This is so the build pipeline can identify when this step needs to run and when it can be skipped. The Setup method returns AndroidProjectFilesModifierContext. For more information, refer to AndroidProjectFilesModifierContext.

For information on when Unity invokes methods in this class, refer to How Unity builds Android applications.

The following example shows how to set some values to build.gradle and AndroidManifest.xml files:

using System.IO;
using UnityEditor.Android;
using Unity.Android.Gradle;

public class ModifyProjectScript : AndroidProjectFilesModifier { public override void OnModifyAndroidProjectFiles(AndroidProjectFiles projectFiles) { // Set minSdkVersion to 28 projectFiles.UnityLibraryBuildGradle.Android.DefaultConfig.MinSdkVersion.Set(28);

// Set android:enabled attribute to 'true' for all launcher activities var launcherActivities = projectFiles.UnityLibraryManifest.Manifest.GetActivitiesWithLauncherIntent(); foreach (var activity in launcherActivities) { activity.Attributes.Enabled.Set(true); } } }

Properties

callbackOrderCallback order when there are multiple implementations of AndroidProjectFilesModifier.

Public Methods

OnModifyAndroidProjectFilesA callback for modifying files in the Android Gradle project after Unity editor creates it.
SetupA callback for setting up prerequisites for modifying Android Gradle project files.