Errors in android.app.Activity.java - java

After setting up Android Studio, I tried to find out how few of the methods work but I can see that Activity class have got a lot of errors.
For example:
// Gives: cannot resolve symbol 'CallSuper'
android.annotation.CallSuper();
// Gives: cannot resolve method 'trackActivity(android.app.Activity)'
private final Object mInstanceTracker = StrictMode.trackActivity(this);
// Gives: cannot resolve symbol 'MainThread'
#MainThread
// **312 errors in android.app.Activity, 579 in android.view.View**
My application works fine though. How can i make those errors disappear and be able to see documentation of structures that cannot be resolved now?
Details on my Android Studio 2.1.3 configuration
Installed in Standalone SDK Manager:
Android SDK Tools
Android SDK Platform-tools
Android SDK Build-tools
SDK Platform and Sources for API 24
SDK Platform, Documentation, Google APIs and sources for API 23
Extras: Android Support Repository, Google Repository and Google USB Driver

Being precise, those aren't errors in the source code for Activity/View it's just that :
Your IDE can't find the class android.annotation.CallSuper in it's classpath.
It cannot resolve method trackActivity in class android.app.Activity.
This is because the SDK is subset of the actual Android platform. The SDK shipped to the developers a.k.a Public API utilizes a lot of platform features a.k.a. Internal APIs, hence you can't find them in your SDK 24 classpath.
So why are all these portions hidden from developers?
It's kept hidden from developers because most of its implementation varies from device to device, plus they wouldn't be required in 99.99% cases (metaphorical figure not actual stats). You might want to have a look here.

add in your build.gradle file:
dependencies {
compile 'com.android.support:support-annotations:22.2.0'
}

This simply means those classes arent on the classpath. When you run an app on a mobile phone or in the emulator the platform make sure the classes are all present.

... i tried to find out how few of the methods work
The easy way to look at Android source code is to just browse it online. For example here is the Activity class.
If you install the "Android SDK Search" plugin for Chrome, it will automatically add source links to the online Javadoc.
How can i make those errors disappear and be able to see documentation of structures that cannot be resolved now?
The only way to view live code without compile errors is to download and build the entire Android Open Source Project.

Related

AndroidManifest.xml and Bluetooth Chat, in Android Studio

A gentleman was kind enough to pass me a link of a repository with bluetooth functionality. I imported it from GitHub. I tried then copying it, but noticed eventually that Android Studio built and organized a different style of directory than that from the github repository. So I deleted the entire directory, and just pasted that of the github depository in.
However, the repository version suffers from the fact that the classes say "Java file outside of source root". Moreover, when I tried to import it, it generates the error "The project is using an incompatible version (AGP 7.3.0) of the Android Gradle plugin. Latest supported version is AGP 7.2.2". I read online I could just update Android Studio instead of downgrade Gradle. When I do the most recent update (I think), Android Studio tells me that the project doesn't use the Gradle build system.
Also, AndroidManifest.xml says that it can't resolve certain activities, such as "MainActivity", which does exist. I think AndroidManifest.xml is in the root folder as it should be.
Any idea what is wrong with my program? At this point, this is just copy-and-pasted from the github Bluetooth Chat program. Is that outdated, etc?
I have spent hours trying to troubleshoot this. Perhaps there is someone with some experience in it.

Can`t run on Android device, because of librabries

I'm launching a game on Android device and getting this error. I`m using up to date Android version, also libgdx.
The library 'jinput-platform-2.0.5-natives-linux.jar' contains native libraries that will not run on the device.
The following libraries were found:
libjinput-linux.so
libjinput-linux64.so
Please help me understand what may cause the problem.
*.so files are native assemblies that are built for a particular architecture. If those *.so files were not built for android (and it seems as if they are not given the error) they will not work.
If there isn't a version for android already built, you can try to write an android version. This other SO question may be of assistance.

How to link a Library project in Android Studio

I recently downloaded the Android Studio and now I am trying to build my project for which I was using Eclipse before. The project also utilizes GoogleMap API.
And in the code where I am using it and importing the library
import com.google.android.gms.location.LocationClient;
it shows me error:
Error:(40, 39) error: cannot find symbol class LocationClient
I have the code for google-play-services_lib which I had linked with the project as library in eclipse and it was working fine.
But I don’t know how to do the same for Android Studio , please help.
Specifically for Google Play Services, first, install the "Google Repository", found in your SDK Manager.
Then, add a suitable dependency on com.google.android.gms:play-services to your dependencies closure:
apply plugin: 'com.android.application'
dependencies {
compile 'com.google.android.gms:play-services:6.1.71'
}
android {
// your project configuration goes here
}
There is a newer version, one that offers more modular dependencies, that you could explore, but I would start with 6.1.71 to get the basics working first before you optimize with the newer version.
Reverting to the old version of the Google Play Services Library, com.google.android.gms:play-services:6.1.71, will work but according to Google in version 6.5 of the library, LocationClient is Deprecated:
Deprecated clients - The ActivityRecognitionClient, LocationClient, and PlusClient classes are deprecated. If you used those APIs in your app and want to call Google Play services 6.5 or higher APIs, you must switch to the new programming model that utilizes GoogleApiClient. For more information about using GoogleApiClient, see Accessing Google APIs.
Use these APIs instead of the deprecated APIs:
If you were previously using ActivityRecognitionClient, call ActivityRecognition instead.
If you were previously using LocationClient, call the APIs in the com.google.android.gms.location package instead.
If you were previously using PlusClient, call the APIs in the com.google.android.gms.plus package instead.
Refer to this post if you'd like an example of using the new GoogleApiClient to retrieve location.
Source
Android Studio uses gradle build system, you should use dependencies instead of library projects.
Find build.gradle in your module directory and add this to the bottom
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
}
Explaination here!
Right click on project name then select to "Open Module Settings".
It will show a window with some tabs.
Go to "Dependencies" tab see if "play-service (com.google.android.gms:play-services:x.x.xx)" is added or not.
if not then click on '+' sign at the right top corner select the "module dependencies".
you will see the list of dependencies choose the "play-service (com.google.android.gms:play-services:x.x.xx)" and click on ok.
than on window apply and ok.
and yes don't forgot to sync the gradle otherwise the changes might not work.
Hope this should solve your probelm.

NotificationManagerCompat Can't be resolved - Android Wear

I'm sure I've just missed something obvious, but I'm at a loss of where to look to solve this.
I'm trying to get started with android wear, and am following the tutorial on this page.
However I can't find any information about which libraries I need to include or where to get them from.
I'm using eclipse and have used the Android SDK manager to download the Android Wear System Image (although I have a G-Watch to test it on) and all the 4.4W stuff, and I've set the project to build against 4.4W but I still get the following error
The import android.support.v4.app.NotificationManagerCompat cannot be resolved
The import android.support.v4.app.NotificationCompat.WearableExtender cannot be resolved
I have the android-support-v4.jar included and android.support.v4.app.NotificationCompat is found OK, but I can't see anywhere in the android wear docs that it says I can get this library and it's driving me nuts.
If someone could point me in the right direction that would be great.
Thanks
There is no android.support.v4.app.NotificationManagerCompat in the support library.
There is in the current one. Examining my android-support-v4.jar shows this class. Make sure that you have the latest version of this JAR downloaded to your machine (from the SDK Manager) and in your project (e.g., copied to libs/ from $SDK/extras/android/support/v4/, where $SDK is wherever your Android SDK is installed).

Use jNAOqi with Android

I'm currently working with Aldebaran-Robotics' NAO (v3.3) and I was wondering if I can use the jNAOqi-SDK within Android to control the robot from a phone or tablet.
Using the SDK with basic java in Eclipse was pretty simple as described in this tutorial, so I tried to do this in ADT Eclipse. I imported the *.jar-file and placed the precompiled libjnaoqi.so from the package in libs/armeabi and libs/armeabi-v7a, but calling System.loadLibrary("jnaoqi") or System.loadLibrary("<jnaoqi>") resulted in the following error at runtime:
I/dalvikvm(2019): Unable to dlopen(/data/data/com.example.hellonao/lib/libjnaoqi.so): Cannot load library: link_image[1995]: failed to link libjnaoqi.so
I checked the filesystem, but the file was in the lib folder as expected, so I guess it has to be a problem with the library itself.
It's just a shot in the dark but do I have to recompile the library using ndk and naoqi?
I quickly abandoned my project but Aldebaran was busy in the meantime. I recently found a thread about it in the Aldebaran community (login required), where two employees (Nicolas Rigaud and Erwan Pinault) mention upcoming Android support.
nrigaud:
there will be a better Java SDK on our next software version. Meanwhile, it's true that it's not that easy to do Java on the robot
epinault:
In the next SDK you will have library (jar/so) for android

Categories