how to make animation legacy in Run time

I used this code given by the official site of unity [URL]

using UnityEngine;
using System.Collections;

public class animFov : MonoBehaviour
{
    void Start()
    {
        AnimationClip fovc = new AnimationClip();
        AnimationCurve curve = AnimationCurve.Linear(0.0f, 60.0f, 10.0f, 90.0f);
        fovc.SetCurve("", typeof(Camera), "field of view", curve);
        fovc.legacy = true;
        GetComponent<Animation>().AddClip(fovc, "animfov");

        GetComponent<Animation>().Play("animfov");
    }
}

It is working in the editor but not in an android device.

Are there any errors on device? You can check this by enabling debug build and attaching console to android player

Yes, I tried that and Animation is turning into legacy but the value of “empty” is true in the android device and false in the editor.
This is the problem but I wonder why.

P.S. - empty:-
AnimationClip.empty
Returns true if the animation clip has no curves and no events.