Version: Unity 6.1 (6000.1)
LanguageEnglish
  • C#

AndroidProjectFiles

class in UnityEditor.Android

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

Stores C# representations of Gradle project files associated with custom modules or plug-ins(libraries).

Use this class to pass Gradle configuration file objects to the AndroidProjectFilesModifier.OnModifyAndroidProjectFiles callback, allowing modifications to Gradle files during the build process. This class does not support modifying Unity's default Gradle and manifest files.

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

public class AndroidProjectFilesExample : AndroidProjectFilesModifier { // Define the path to the Gradle file private string _myLibBuildGradle = Path.Combine("unityLibrary", "customPlugin", "build.gradle"); // Configure the required settings/outputs to modify the Android project files public override AndroidProjectFilesModifierContext Setup() { // Initialize the context for modifying project files AndroidProjectFilesModifierContext projectFilesContext = new AndroidProjectFilesModifierContext();

// Add the Gradle file to the output projectFilesContext.Outputs.AddBuildGradleFile(_myLibBuildGradle);

// Add a custom file to the output projectFilesContext.Outputs.AddFileWithContents("CustomOutput/Config.txt");

return projectFilesContext; }

// Modify the Android project files public override void OnModifyAndroidProjectFiles(AndroidProjectFiles projectFiles) { // Create a build.gradle file var buildGradleFile = new ModuleBuildGradleFile(); projectFiles.SetBuildGradleFile(_myLibBuildGradle, buildGradleFile);

// Add contents to the build.gradle file buildGradleFile.Android.DefaultConfig.VersionName.Set("Example Version Name");

// Check if the Gradle file exists in the project if (projectFiles.AdditionalLibrariesBuildGradleFiles.ContainsKey(_myLibBuildGradle)) { // Log a message indicating the Gradle file was found Debug.Log($"Gradle file found: {_myLibBuildGradle}"); } else { Debug.LogWarning($"Gradle file not found: {_myLibBuildGradle}"); }

// Use the SetFileContents method to create a custom file string customFileContent = "This is a custom configuration file created during the build process."; projectFiles.SetFileContents("CustomOutput/Config.txt", customFileContent);

Debug.Log("Custom file created successfully."); } }

Properties

Property Description
AdditionalLibrariesBuildGradleFilesA representation of the build.gradle files that were added to plug-ins (libraries) that didn't have a build.gradle file.

Public Methods

Method Description
GetDataGets data that was set in the Setup method.
SetBuildGradleFileSets a new build.gradle file.
SetFileContentsSets the content of a new file to the specified bytes.
SetGradlePropertiesFileSets a new gradle.properties file.
SetGradleSettingsFileSets a new settings.gradle file.
SetManifestFileSets a new Android Manifest file.