Cannot import google cloud endpoints client library class in Android project - android

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

Related

How Can i Import example application from developer.android.com into Android Studio

I have downloaded the CustomView.zip from developer android page.
I've tried to import this into Android Studio 2.2.0.12. But I am NOT able to do it.
I have also tried to create a empty project in order to import only the sources and XML. It does´t work either, I get a lot of duplicates XML definitions and even after resolving the duplicates the App crashes with some inflate exception.
So, i´m wondering, How can I import this into Android Studio in order to have a working project and run it to see the behavior and also to debug it
Thanks in advance.
Looking at the sample file, stupidly, it doesnt include any of the standard android framework files (gradle, manifest etc), so Android Studio will not be able to automatically import it.
To get round this you should create a new blank project, leave the mainactivity that is generated.
Then go in to the file structure of the new project and copy in the files from the sample in to the corresponding files. Make sure you overwrite the files in the new project.
Then go in to the code base in Android Studio and delete any imports that cant be found due to incorrect package names. Re import these (alt + enter on mac) with the correct package names and then build and you should be good to go.

Import library project to Android Studio how to steps

currently I'm trying to implement and apply a pull to refresh list view for my sample app. Now I found out about chrisbanes pull to refresh here. Yes I know it's no longer maintaned but I can't find any alternatives. Anyway I tried to read a lot of questions about importing a project and I think I'm always lost about it especially with the gradle structure.
What I tried so far is to import the project in eclipse then gradle export and copy paste it on a directory named libraries following the steps in this link. I get an error saying Cannot create class-file.
As for the other test I've done I always get a gradle error. I forgot the exact error message but most of it are because of gradle.build.
Now can anyone tell me on the steps on how I can import this project library for my Android Studio project on a step by step basis? My apologies for asking too much.

android.support.v13.dreams.BasicDream cannot be resolved

I'm trying to work on extending BasicDream which exists in package: android.support.v13.dreams. I have tried downloading all most all android version (just trying luck to get it working) but I'm unable to import it. i.e. On
import android.support.v13.dreams.BasicDream; statement I'm getting an error:
The import xxxxxx... cannot be resolved.
I tried copying my sdk/extras/libs/../android-support-v13.jar in my libs folder and added to build path but found this package does not show dreams. While typing import statement I'm able to see v13 i.e. I can write import android.support.v13.app.*; but it does not have dreams/basicdream.
Tried google and do found the source code of this class but no idea why my jar file does not have these classes or how to use it. Please suggest what am I missing here.
Update: Finally I figured out that BasicDream was part of Android Support Library version 13 Link: BasicDream source codeshipped with android 4.1.2 however latest Android Support Library version 13 does not have Basic Dream.support library v13 class list
As I'm working on some native functionality, I downloaded BasicDream source code from the link mentioned above and included in same folder where I have my other source files. Updated the package to my application package
In your case probably the best way to get it is to check code of this class on GrepCode and manually resolve (copy) all dependencies. Good luck!

Android LVL won't Import into Eclipse

I'm trying to get the Android LVL (App Licensing) setup to work with my software... and I cannot get it to import into Eclipse at all. The documentation says, "add the library folder to your workspace"... but it won't let me. I have rev. 2 downloaded... but when I try to import the project (from /android-sdk-macosx/extras/google/play_licensing/library) it shows up greyed-out in the projects list and won't import. Can someone please help me out here?
Just drag the sources into your project. The intention of the LVL is that you build your own sources and make changes (to try to thwart people that modify your binary by looking for LVL-specific bits).

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.

Categories

Resources