IBM sponsored and was the primary contributor of resources to an independently developed Java work-alike called Apache Harmony. (about JDK 1.5 level, IIRC) Apache Harmony was, naturally, under the Apache license.
Google wanted something like Java for Android, so Google used Apache Harmony.
Sun was okay with Google having something like Java in Android and had said so. (perhaps reluctantly)
Oracle sees Sun for sale, and envisions a big "sue google" sign on Sun's back. Oracle buys Sun, to get Java and sue Google. Very soon after acquisition this becomes apparent. James Gosling leaves Oracle for reasons that were not quite clear at the time, but soon become clear.
Oracle claimed Google had used Java code. But Android had Apache Harmony.
So Oracle changes its argument to . . . But the APIs!!!
(Groklaw had documented all this back in the day.)