PostProcessBuild_Android.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if UNITY_ANDROID
  2. using UnityEngine;
  3. using UnityEditor.Android;
  4. using System.IO;
  5. using System.Text;
  6. //-----------------------------------------------------------------------------
  7. // Copyright 2012-2021 RenderHeads Ltd. All rights reserved.
  8. //-----------------------------------------------------------------------------
  9. namespace RenderHeads.Media.AVProVideo.Editor
  10. {
  11. public class PostProcessBuild_Android : IPostGenerateGradleAndroidProject
  12. {
  13. public int callbackOrder { get { return 1; } }
  14. public void OnPostGenerateGradleAndroidProject( string path )
  15. {
  16. GradleProperty( path );
  17. }
  18. private void GradleProperty( string path )
  19. {
  20. #if UNITY_2020_1_OR_NEWER || UNITY_2020_OR_NEWER
  21. // When using Unity 2020.1 and above it has been seen that the build process overly optimises which causes issues in the ExoPlayer library.
  22. // To overcome this issue, we need to add 'android.enableDexingArtifactTransform=false' to the gradle.properties.
  23. // Note that this can be done by the developer at project level already.
  24. Debug.Log("[AVProVideo] Post-processing Android project: patching gradle.properties");
  25. StringBuilder stringBuilder = new StringBuilder();
  26. // Path to gradle.properties
  27. string filePath = Path.Combine( path, "..", "gradle.properties" );
  28. if( File.Exists( filePath ) )
  29. {
  30. // Load in all the lines in the file
  31. string[] allLines = File.ReadAllLines( filePath );
  32. foreach( string line in allLines )
  33. {
  34. if( line.Length > 0 )
  35. {
  36. // Add everything except enableDexingArtifactTransform
  37. if ( !line.Contains( "android.enableDexingArtifactTransform" ) )
  38. {
  39. stringBuilder.AppendLine( line );
  40. }
  41. }
  42. }
  43. }
  44. // Add in line to set enableDexingArtifactTransform to false
  45. stringBuilder.AppendLine( "android.enableDexingArtifactTransform=false" );
  46. // Write out the amended file
  47. File.WriteAllText( filePath, stringBuilder.ToString() );
  48. #endif
  49. }
  50. }
  51. }
  52. #endif // UNITY_ANDROID