I am trying to build a FM Radio kind of application and I cloned this Google Respository for the reference.
However There are few classes in the imports which are missing in android sdk. I tried changing compileSdkVersion from 18 to 24 but android.jar seems to be missing these Following imports:
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.AudioManager.OnAudioPortUpdateListener;
import android.media.AudioMixPort;
import android.media.AudioPatch;
import android.media.AudioPort;
import android.media.AudioPortConfig;
import android.media.AudioDevicePort;
import android.media.AudioDevicePortConfig;
Where exactly are these classes and how can i import them ?
The Strange thing about them is they are present as .java files in sources/android-xx but not in actual .jar file.
The sample is showing errors and I am not able to proceed. Please guide me how to resolve this issue.
You can see from the Android source code that these classes are "hidden" from the jar using the "pseudo-annotation":
/* #hide */
For example, see here and here.
This annotation controls what will appear in the runtime Android.jar.
Note, sometimes these hidden classes are later included as part of the official SDK.
Refer to:
https://commonsware.com/blog/2018/01/18/think-hard-about-hide.html
What does #hide mean in the Android source code?
What exactly does Android's #hide annotation do?
Related
I imported the 'SQLiteDatabase' class present in 'android.database.sqlite' package, into my project.I went into the class declaration to find the opendatabase function, but i noticed that the class was full of errors and was importing certain undefined/undeclared classes, like:
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.database.sqlite.SQLiteDebug.DbStats;
import android.os.SystemProperties;
These classes are used throughout the 'SQLiteDatabase' class.
I tried to invalidate caches and restart the AS IDE, but the error still persisted.
I went into the sdk manager and downloaded all the required core android packages, but still nothing changed.
Finally, I checked out the documentation to see if something was wrong with my sdk. The documentation too did'nt recognize these import calls. like, android.annotation package does'nt even declare a IntDef or IntRangeclass, which has been imported in SQLiteDatabase. It gives the same, could resolve symbol error.
After doing research for a while, I found an answer to my own question. I'm answering just in case it might help others stuck in this error/problem. The classes that were imported are hidden classes, tagged with annotation #hide.
Refer to this article for more.
Hidden classes (even if they are public in the Java sense) are removed from android.jar file containing specific platform API dependencies, like API level 27. Hence you get the error when you try to import something like Nonnull, service manager, etc . Hidden classes are those that Google does not want to be part of the documented public API.
I was trying to use the snippet from 2nd answer of the following post:
How do you turn off share history when using ShareActionProvider?
Which can be dowloaded from here and after adding ActivityChooserView.java along with other files to my project, I cannot resolve:
import android.support.v7.internal.widget.ListPopupWindow;
Import of android.support.v7.appcompat does not give any errors.
Where can I find android.support.v7.internal.widget.ListPopupWindow class?
I googled it and found nothing :)
I am compiling for android v23 and using appcompat.v7 of the same version.
As you can see here the package name is android.support.v7.widget, so the correct import is:
import android.support.v7.widget.ListPopupWindow;
ListPopupWindow was moved from android.support.v7.internal.widget to android.support.v7.widget in v7 appcompat library v21.0.0.
To fix the issue change the import to the updated one.
I am trying to use the class BluetoothAvrcp from the package android.bluetooth but the import fails. It can't seem to file the class.
import android.bluetooth.BluetoothAvrcp;
Is there anything that I need to add before being able to use that one?
SDK 22.
Thank you.
It happens that these classes requires to build the android rom from the source.
Follow the following link to build from the source.
https://source.android.com/source/index.html
In IntelliJ you can press Ctrl-Alt-O to import namespaces for classes that are being referenced. I did this and it did import some classes but not others. I'm actually using Android Studio which is based on IntelliJ. The class I'm trying to import is IBinder but when I hover over the class name it indicates:
Cannot resolve symbol 'IBinder'
Since this is based on Gradle, am I suppose to manually include something in the build.gradle? Or does Android Studio automatically add the dependency for the classes I want to use? IBinder is a rather standard interface, so I can hardly believe I need to add something special.
You mean android.os.IBinder?
A simple import android.os.IBinder should work, shouldn't it?
BTW, on my Android Studio (default) installation, Ctrl-Alt-O organizes imports, but does not import them.
I downloaded an Android Project and got some errors.
How can I use this imports in Android?
import com.android.internal.telephony.IccSmsInterfaceManager;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SMSDispatcher;
When I import this, I got errors like these:
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
Later in the code there are:
Phone phone = PhoneFactory.getDefaultPhone();
With the error:
Multiple markers at this line
- Phone cannot be resolved to a type
- PhoneFactory cannot be resolved
And so on...
I tried to fix it with the https://stackoverflow.com/a/16377968/3203914
but I did not work for me.
Can please someone tell me how to fix it?
Thanks!
How can I use this imports in Android?
Those are not part of the Android SDK. If you are editing the Android source code, the build process for it should resolve those imports. If you are trying to write an Android app, you cannot directly reference them. In fact, com.android suggests they are part of a separate app, not yours and not the Android framework.
CommonsWare is correct, its not in the SDK so you cannot directly reference them. You will either have to
Import all of the android source code, which will resolve these issues
Import the specific project containing this code, then set up your code as a dependency
Stop using those packages