MENLO PARK, Calif. — A federal appeals court has overturned a decision in a long-running legal battle over whether Google infringed on Oracle’s Java programming language to build its hugely popular mobile operating system, Android.

The court said Google’s use of Java language was “not fair” and sent the case back to trial to determine damages.

Oracle had originally sought $9 billion. The court said Android helped Google earn $42 billion in advertising revenue since the first Android phone went on sale in 2008.

Oracle hailed Tuesday’s ruling, saying the opinion by the U.S. Court of Appeals for the Federal District “upholds fundamental principles of copyright law.”

A Google spokesman said the ruling was disappointing and that it “will make apps and online services more expensive for users.” The company said it is considering its options.

The court weighed whether Google’s copying of 11,500 lines of Java code at the core of its Android operating system amounted to fair use and found it did not.

Judge Kathleen O’Malley, writing for the three judges hearing the case, rejected Google’s argument that use of the code was non-commercial; found it wasn’t “transformative” because the copied code performed exactly as Oracle intended; and that Google’s development of Android robbed Oracle of the ability to make money from its Java SE platform for mobile devices.

In fact, Java SE had already been in phones from companies like BlackBerry and Nokia. The court said Amazon used the fact that Android was given out free to manufacturers to negotiate a steep discount on Java SE for use in an early Kindle tablet. Amazon later switched to using a modified version of Android.

“There is nothing fair about taking a copyrighted work verbatim and using it for the same purpose and function as the original in a competing platform,” O’Malley wrote.

Shares of Google parent Alphabet fell 4.5 percent Tuesday to close at $1,006.94, while Oracle shares also fell 2.4 percent to close at $45.38.