After weeks of struggling with the documentation and plenty of forums I found out how to use both the Drive API Client Library for Java and Google Sheets API. I feel that the documentation especially for android is very lacking so I thought it would be useful to make a post explaining how to import the API's for Android. This is the post I wish I could have found when I started with these two libraries, I hope this helps someone who might have run into my problems..
问题:
回答1:
Note: this is for Android only, and directed for Android Studio. The configuration descirbed below is what i am using, although there may be some unnecessary files included it does nonetheless work.
So first, the functionality that importing these two APIS will give is access to a users Google Drive, and to edit Google Spreadsheets on that account. There are two "versions" of the Drive API for Android, one made specifically for Android and another for any Java environment. Although the one made specifically for Android is simpler to use and is better integrated with Android it has one major drawback.
Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.
This means your app can only access and edit files it has itself created, for this reason i chose to use the Google APIs Java Client. As for the Google Sheets API there are no real alternative versions, just itself.
Now the hardest time i had was trying to find out which files i needed to import, the documentation on this is hazey so here are the files needed.
Put all these files in the app\libs
directory of your app.
To use Drive API Client Library for Java
First "Download the Drive API v2 Client Library for Java." In readme.html
it describes what dependencies are needed for android.
Use the following jars.
`google-api-client-android-1.19.1.jar (for SDK >= 2.1)
google-http-client-android-1.19.0.jar
gson-2.1.jar
protobuf-java-2.4.1.jar`
Also include google-api-services-drive-v2-rev161-1.19.1.jar
To use Google Sheets API version 3.0
Download gdata library from here, this includes spreadhseet jars and other gdata libraries like maps, finance, docs, calendar, etc..
In the gdata\java\lib use the following files.
`
gdata-client-meta-1.0.jar
gdata-core-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.19.1.jar
google-api-client-android-1.19.1.jar
google-api-services-drive-v2-rev158-1.19.1.jar
google-http-client-1.19.0.jar
google-http-client-android-1.19.0.jar
google-http-client-gson-1.19.0.jar
google-oauth-client-1.19.0.jar
guava-18.0.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jsr305.jar
protobuf-java-2.4.1.jar
gdata-base-1.0.jar
gdata-client-1.0.jar
`
Download javamail, this is made specifically for android`
mail.jar
activation.jar
activation.jar`
Now that you have all these in your app\lib directory your build.gradle should include the following(add these in yourself):`
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/gdata-base-1.0.jar')
compile files('libs/gdata-client-1.0.jar')
compile files('libs/gdata-client-meta-1.0.jar')
compile files('libs/gdata-core-1.0.jar')
compile files('libs/gdata-spreadsheet-3.0.jar')
compile files('libs/gdata-spreadsheet-meta-3.0.jar')
compile files('libs/google-api-client-1.19.1.jar')
compile files('libs/google-api-client-android-1.19.1.jar')
compile files('libs/google-api-services-drive-v2-rev158-1.19.1.jar')
compile files('libs/google-http-client-1.19.0.jar')
compile files('libs/google-http-client-android-1.19.0.jar')
compile files('libs/google-http-client-gson-1.19.0.jar')
compile files('libs/google-oauth-client-1.19.0.jar')
compile files('libs/gson-2.1.jar')
compile files('libs/guava-18.0.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jsr305.jar')
compile files('libs/mail.jar')
compile files('libs/protobuf-java-2.4.1.jar')`
Final step!
Because of the sheer number of methods that these imported jars have we need to make our app multi-dexable, this process is very straight forward and is described here.Once you've done this your all set to start using the Drive and Spreadsheets API, if you found this useful up vote so other can see!