Android error: package android.os does not exist

Recently, I met a similar case in Android Studio 3.2.1 Ubuntu/Linux version.

I am quite sure about the issue shall be related to the Android SDK installation,because I build the same project in Android Studio of my Windows 10 laptop.

Issue: Java compiler error at Android studio

error: package android.os does not exist
error: package android.media does not exist
error: package android.content does not exist
error: package android.util does not exist
error: cannot find symbol variable Log
error: cannot find symbol class Context
error: cannot find symbol class AudioRecord

Solution: The android.jar which was mentioned at the build.gradle file was not installed at the /sdk/platforms/ directory. See the android.jar dependency at my build.gradle file below(which caused the issue),

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files(sdkDir+'/platforms/android-24/android.jar')
}

Install the correct android platform(correct API level as mentioned in the build.gradle file,if any) and rebuild the project.


I suggest to use AGP Upgrade assistent. I often have probs upgrading gradle. This time with artic fox and java 11 it I got all those infamous android.* not found errors.

Then I discovered that neat AGP Upgrade assistent (in tools since Studio 4.2) - and it did what it should and everything is now using gradle 7 and compiles again.

About time such a tool was introduced - and I just saw about half a year too late ;)