I would like to integrate my app with a variety of file storage services. I followed the quickstart instructions for the Drive sdk, which adds a bunch of jars to my projects libs directory. Additionally, the Dropbox sdk requires the following list of jars:
commons-logging-1.1.1.jar
dropbox-android-sdk-1.5.3.jar
httpclient-4.0.3.jar
httpcore-4.0.1.jar
httpmime-4.0.3.jar
json-simple-1.1.jar
Once all of these are added to my project, I get the following error when I try to run:
Dex Loader] Unable to execute dex: Multiple dex files define
Lorg/apache/http/entity/mime/FormBodyPart;
If I remove the httpmime jar added for Dropbox, my project runs fine. But is this a safe way to resolve the conflict? Is there an alternative method with which I can build my project and include all the required jars?
Assuming no version conflicts this would work fine. Compare the httpmime-4.0.3.jar to the httpmime jar that Drive added to your libs directory. If they're the same, then it's fine. If they're different, then you'll have to find out the differences between the two and insure that they're not breaking changes. As a last resort you could also repackage one of the SDKs with its required version of httpmime in a jar selectively obfuscated with ProGuard, though that's a hassle.
If you are developing with Eclipse, consider using Google Plugin for Eclipse. It provides a way to add any of the Google's SDK to your app. All the jars are added automatically.
Related
I've just followed exactly what was said in this tutorial and ran the command
/usr/local/google_appengine/endpointscfg.py get_client_lib java -bs gradle helloworld_api.NewsApi
I know my NewsApi service works, I've tested it on the Google APIs explorer.
I get a success message: API client library written to ./getNews-v1.zip
I extracted the zip and found the following files inside the folder (getNews):
No JAR file exists!! What do I use to set up the library in my Android client?
Any ideas? Thanks!
If you want a sources JAR and included dependencies to include in your project use '-bs default' or simply omit that option. Using '-bs gradle' or '-bs maven' assumes you are going to use one of those build tools to build a classes JAR yourself. The 'endpointscfg.py' of course won't compile sources to class files for you as it doesn't have knowledge of any Java environment.
More info in the docs:
https://cloud.google.com/appengine/docs/python/endpoints/endpoints_tool
Google's instructions for using the Play Service API (for example) say:
Copy the /extras/google/google_play_services/libproject/google-play-services_lib library project into the source tree where you maintain your Android app projects.
Note: You should be referencing a copy of the library that you copied to your source tree—you should not reference the library from the Android SDK directory.
This seems ugly to me - why not reference it from the SDK directory? Is there some technical reason for this? Or is it so that you have explicit control over when it gets upgraded?
I'd like to point out that this is entirely a limitation of Eclipse, and it is indeed ugly.
The problem is that this library contains resources in addition to source code. Eclipse can only deal with libraries packaged as jar files, which, for the purposes of Android development, cannot contain resources.
So, in order for the library's resource to be compiled into the application, the library's source code, with the resources, must be added to your project.
If you move your build to Maven, and use an IDE that 'understands' Maven, then you can compile a library that contains resources as an 'apklib', and treat it as an external library, in a manner similar to a jar file.
The new Gradle-based build system is built on Maven primitives, but uses a different format for this, 'aar'. Hopefully, it will eventually also support apklib so that Maven builds and Gradle builds can inter-operate.
I just went through the exercise of converting an Android application to a Maven build, including the use of some apklibs. I can tell you that Eclipse with the m2eclipse plugin does not handle apklibs properly. Both IntelliJ and the new Google Android Studio (based on IntelliJ) do handle apklibs with no issues.
It's not about "Play Services Library" specifically. Just like any other libraries that the project makes use of, this library should be referenced from project's source tree.
In this case the external library is in the Android SDK directory and referencing from there is not a good practice too. So yes, it can be called "a technical reason".
Used libraries (Play Services library in this case) shouldn't be referenced from anywhere other than the project's source tree.
In order to integate my app with GDrive I have followed the tutorial on https://developers.google.com/drive/quickstart-android
In step 3 of the tutorial, the tutorial recommends to install the Google Eclipse plugin to take care of the library setup (this plugin let's you choose which's Google API's to use and creates the /libs folder including the jars for you).
The tutorial shows how to take a picture and upload it to Google Drive.
After working through the tutorial I decided to extend the example: since my app works with Google Spreadsheets I added the spreadsheets API (using the Google Eclipse Plugin) to the example.
The application compiles but on run-time I do get the following error:
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Ljavax/annotation/CheckForNull;
My feeling is that some libraries are conflicting, but these libraries are all calculated using the Google Eclipse plugin? How is this possible and how should I resolve this issue?
My (generatd) libs folder looks like this (contains the Google Drive API v2 and Spreadsheets API):
gdata-client-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.12.0-beta.jar
google-api-client-android-1.12.0-beta.jar
google-api-services-drive-v2-rev55-1.12.0-beta.jar
google-collect-1.0-rc1.jar
google-http-client-1.12.0-beta.jar
google-http-client-android-1.12.0-beta.jar
google-http-client-gson-1.12.0-beta.jar
google-http-client-jackson-1.12.0-beta.jar
google-http-client-jackson2-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
gson-2.1.jar
guava-jdk5-13.0.jar
jackson-core-2.0.5.jar
jackson-core-asl-1.9.9.jar
jsr305-1.3.9.jar
jsr305.jar
Thanks for any help,
Peter
I had the same problem. Removing the jsr305.jar from the libs folder solved the problem for me.
Remove the bin and gen folders and Build the project
or
check multiple private libraries added to your project
or
check whether the multiple play services added to your project
I have included the Google gdata finance jar in my Android project (included the jar file in the build set). However still when I make any calls to functions in that jar, I still get a NoClassDeffound Exception. I believe this means that during execution the particular class is not being found by the emulator. Any ways I can fix this problem?
And I am including the com.google.gdata.client.finance.* via the import statements.
UPDATE: I solved the problem. It was more gdata specific. The problem was that I was not including the core gdata files: gdata-client, gdata-client-meta, gdata-core, and gdata-media.
It would appear that your JAR is not being packaged with your application, for some reason. Make sure the JAR is in the libs/ directory of the project.
I have a project that I would like to add external libraries to (and have them packaged with the application) but I am not sure it is happening. I read on this link:
https://developer.android.com/guide/appendix/faq/commontasks.html
how to, but they do not show up in any of the /data/data/project directories. Does anyone know how I can confirm that the libraries were in fact added to the project for use at runtime? Thanks.
If you include jars as External Jars under your project's Java Build Path, then the classes will be converted to Dalvik format and be made available in your project's classes.dex file, packaged into the .apk.
To confirm they are available, attempt to use something from the jar (Eclipse should suggest the relevant import when you first supply a class name) build and run the app and see if it works? If it works in development (e.g. from 'run' in Eclipse) then it will also work when the app is built in release and distributed as an APK.
You can also place jar under one of your source folders (perhaps creating special "libs" one) and adding it to build path.
Be warned - external libraries (which are compiled against some version or other of the libraries in a Java JDK) may sometimes have problems when running under android. This is because the Dalvik runtime has its own Java framework libraries, which provide most (but not all) of the Java APIs in the standard JDK Java framework libraries.
You should really recompile any external library against the android libraries so that you can see any missing APIs at compile time - and fix the issues there and then. Otherwise you run the risk of runtime errors under Dalvik when you call the external library from your Android app. See http://geekswithblogs.net/cyberycon/archive/2011/05/17/using-external-libraries-with-android.aspx
for more details.