Importing google client dependencies - android

I'm trying to add some YouTube OAuth2.0 authorization for an Android project I'm working on using Android Studio. I got some sample code from here http://bit.ly/1SI805S. I'm pretty sure I linked to it from a Google developers site. I'm trying to add some libraries to take care of the dependencies but it isn't recognizing them. Here are the dependencies:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.oauth2.Oauth2;
import com.google.api.services.oauth2.model.Tokeninfo;
import com.google.api.services.oauth2.model.Userinfoplus;
I downloaded a .jar for the com.google.api.services dependencies and that is working fine. I found the file on the Google developers site and it's google-api-services-oauth2-v2-rev103-1.21.0.jar. However, all of the api.client jars I've found are not working. I put them in the libs folder and add compile files to the build.gradle but it won't recognize the imports.
The jars I've used thus far are
google-api-client-util-1.2.3-alpha.jar
google-api-client-extensions-1.6.0-beta.jar
google-api-client-auth-1.2.3-alpha.jar
Is there anything I'm missing? I've found these files in different parts of the net. I've looked through maven repositories and I just found a site, http://www.java2s.com/Code/Jar/g/Downloadgoogleapiclientutil121alphajar.htm, but I don't know that it's helpful. There's some api.client stuff I downloaded from the Google Developers site but that doesn't look like anything I need and it doesn't resolve the dependencies.

Please follow the third apprach in my link, since your library is available online (remotely) as you see in the picture below. Android studio will recognize your dependencies if you add them in their standard ways. In general, there are three standard ways. Please read this link https://stackoverflow.com/a/35369267/5475941. In this post I explained how to import your JAR files in Android studio and I explained all possible ways step by step with screenshots. I hope it helps.
Also, check your build.gradle (Moducle: app) and make sure your remote libraries are compatible with your current SDK. For example my SDK is 23.1.0:
Google HTTP Client Library for Java. Functionality that works on all supported Java platforms, including Java 5 (or higher) desktop (SE) and web (EE), Android, and Google App Engine.
https://github.com/google/google-http-java-client
Project metadata download:http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc.pom
Binary download:http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc.jar
Source download: http://repo1.maven.org/maven2/com/google/http-client/google-http-client/1.16.0-rc/google-http-client-1.16.0-rc-sources.jar
The classes that you are searching for are here:

Related

android.media package missing few classes in sdk-platforms[android.jar]

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?

Spotify Android SDK - Cant import player library

I am trying to integrate spotify with my android application. I am using their Android SDK with Android Studio. I followed the tutorial on their official developer guide. I can import and use the authentication api (import com.spotify.sdk.android.authentication;) but cant import the player api (import com.spotify.sdk.android.player;)
Anybody faced this problem or any leads?
EDIT:
I added these dependencies in build.gradle file:
// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta10#aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta10#aar'
Now I tried to try out the demo code mentioned in the link above. But I am getting error in these imports.
import com.spotify.sdk.android.player.Spotify;
import com.spotify.sdk.android.player.ConnectionStateCallback;
import com.spotify.sdk.android.player.Player;
import com.spotify.sdk.android.player.PlayerNotificationCallback;
import com.spotify.sdk.android.player.PlayerState;
However I can import the authentication related imports.
import com.spotify.sdk.android.authentication.*;
Either the player library is not getting imported properly or the import definitions have changed in 'com.spotify.sdk:spotify-player:1.0.0-beta10#aar' version, since the demo code that has been given is for 'com.spotify.sdk:spotify-player:1.0.0-beta9#aar' version.

Cannot import google cloud endpoints client library class in Android project

I'm having difficulty getting Google Cloud Endpoints working. I have an Python endpoints project running on GAE and it works perfectly using the api explorer. However I'm struggling to properly generate the client library and use it in my android app. I've tried a number of sample projects and have the same problem every time; I can't import and use the model classes from the client libraries.
Here's what I'm doing (for this example I'll use the helloworld api python sample at https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-python)
Unzip the sample code
Generate the client library by navigating to folder and running
<gae-sdk>\endpointscfg.py get_client_lib java helloworld_api.HelloWorldApi
Unzip the generated folder and copy into root of project in eclipse
In Eclipse add "your_app_id_appspot_com-helloworld-v1-20140310110152-java-1.17.0-rc-sources.jar" to build path (Right click the JAR> Build Path>Add to Build Path)
At this stage, I can import com.appspot.your_app_id.helloworld.model.*but I cannot import com.appspot.your_app_id.helloworld.model.Greeting
Can anyone shed any light on what's happening here? I have tried many different ways to get this to work but have the same problem every time.
Many thanks,
Tom
The problem is that by default, the generated zip file only contains a sources jar, not an actual compiled library jar which your Android app can use.
Here's the solution:
In your backend api folder (from the same place where your app.yaml is located), generate the client library as a gradle library, like so:
<gae-sdk-path>\endpointscfg.py get_client_lib java -bs gradle helloworld_api.HelloWorldApi
You'll now have a helloworld-v1.zip. Unzip this (either right here or in somewhere convenient like ~/temp)
This will create a folder called helloworld, which should have a build.gradle in there along with a src folder.
Build your client library using "gradle install" in this folder.
Copy build/libs/helloworld-v1-1.X.X-SNAPSHOT.jar into your Android app's libs folder.
Add it as a library in Android Studio by right-click/add-as-library.
Your classes should now resolve correctly.
Step 4 should install the just-built client library into your local maven repository. You can follow the instructions in readme.html in the helloworld/ folder you extracted to integrate directly with your Android app's gradle build system instead of copying the jar your built manually.
This post said that there is a bug with Android Studio's Add As Library: Android Studio: IncorrectOperationException when 'Add as Library' is clicked whilst trying to configure Google Apps Endpoints client libraries
Not sure if it applies to Eclipse.
I was able to solve this problem and have provided the solution below.
I switched to Android Studio Preview 0.4.6 from Eclipse which helped get rid of some of Googles library import issues(through I guess build.gradle config). I feel it was not a problem of Eclipse which I was using earlier.
I was able to to fix the import issues. The code on the tutorial segments on the official Google docs needs to be put in sync.
The solution is to roughly do the following changes:
In MainActivity.java, replace:
HelloGreeting with HelloworldApiGreeting
In MainActivity.java, add the following at the top:
import android.widget.Toast;
import android.os.AsyncTask;
import android.util.Log
import com.appspot.androidbackend1.helloworld.model.HelloworldApiGreeting;
import com.appspot.androidbackend1.helloworld.model.HelloworldApiGreetingCollection;
In MainActivity.java, comment the following at the top:
import com.appspot.androidbackend1.helloworld.Helloworld.Greetings.Multiply;
import com.appspot.androidbackend1.helloworld.model.HelloGreeting;
In Application.java, add the following at the top:
import com.appspot.androidbackend1.helloworld.model.HelloworldApiGreeting;
In Application.java, replace:
HelloGreeting with HelloworldApiGreeting
Hope this saves time for others

Google APIs: downloading and reading the sources

My goal is to understand every single bit of the following example:
http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager
I can run the example successfully, but now I want to understand every single
line of code in the example. For as far as the standard android APIs I can look
up their function by googling them up and looking at developer.android.com, but
for the other lines that come from the Google APIs I cannot find the up-to-date
1.6 sources on the web for clsses such as the following:
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.InputStreamContent;
import com.google.api.client.util.DateTime;
import com.google.api.services.picasa.PicasaClient;
import com.google.api.services.picasa.PicasaUrl;
import com.google.api.services.picasa.model.AlbumEntry;
import com.google.api.services.picasa.model.UserFeed;
I cannot see any JavaDoc in eclipse, so the only alternative I have to learn about
these is to look at the code. How can I use mercurial to sign out up to date copies
of the Google APIs including those classes that can be used on android?
I think, since I cannot find what I want on the web is to grab the sources
as that seems to be the only way to learn what I need, but I don't know how
to use hg to do this, because I don't know how to use hg nor the site where
I can get the sources from.
Thank you for your help,
John Goche
If you are using Eclipse the following post might be useful:
Attaching Android platform source in Eclipse
I had the same problem before and read through the previous answer on how to setup the build environment for Android. Unfortunately, the build environment so far does not support Windows Box. So a quick way is to download the source for a particular android version (e.g. 2.2) and extract to a local directory. In your Eclipse project, right click on android.jar to open the properties dialog. click on Java Source Attachment and enter the root directory of your source. Then refresh your project. You're set to debug through the source on Windows.

how to import android licensed project in eclipse?

Can anyone help me to know how to import licensed project, while trying... the following classes cannot be imported.
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;
import com.android.vending.licensing.AESObfuscator;
Any help will really be appreciated. Thanks
The latest version of the LVL seems to require
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.ServerManagedPolicy;
import com.google.android.vending.licensing.AESObfuscator;
instead of
import com.android.vending.licensing.LicenseChecker;
...
(as the current document tells me to do)
It took me a half day to figure this out.. haha
LVL library can be downloaded using the SDK Manager
Link
The License Verification Library (LVL) is a collection of helper classes that greatly simplify the work that you need to do to add licensing to your application. In all cases, we recommend that you download the LVL and use it as the basis for the licensing implementation in your application.
The LVL is available as a downloadable component of the Android SDK. The component includes:
The LVL sources, stored inside an Android library project.
An example application called "sample" that depends on the LVL library project. The example illustrates how an application uses the library helper classes to check and enforce licensing.
To download the LVL component into your development environment, use the Android SDK and AVD Manager. Launch the Android SDK and AVD Manager and then select the "Market Licensing" component, as shown in the figure below. Accept the terms and click Install Selected to begin the download.

Categories

Resources