[英]How to import Google API in Android Studio
我正在嘗試使用Android Studio。 我想在我的項目中使用Drive API。 在eclipse中,有一個用於Eclipse的Google插件,但Android Studio呢? 到目前為止有人試過嗎?
Bellow你可以找到Google Drive的最新版本(2014.12.28):
//Google Drive API
compile 'com.google.android.gms:play-services:6.5.+'
compile 'com.google.api-client:google-api-client-xml:1.18.0-rc'
compile 'com.google.http-client:google-http-client-gson:1.18.0-rc'
compile 'com.google.api-client:google-api-client-android:1.18.0-rc'
compile 'com.google.apis:google-api-services-drive:v2-rev155-1.19.0'
要查看上一版本,請嘗試以下鏈接:
https://developer.android.com/google/play-services/setup.html
https://code.google.com/p/google-api-java-client
https://developers.google.com/api-client-library/java/apis/drive/v2
http://mvnrepository.com/artifact/com.google.apis/google-api-services-drive
我處於同樣的情況,不得不在這里找到有關Gradle如何找到正確的依賴關系並排除所需的信息。 這里是build.gradle文件依賴項中所需的行
// Replace 'dependencies' in your build.gradle file with the following
// or add these to whatever other dependencies you have.
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile('com.google.api-client:google-api-client-xml:1.17.0-rc') {
exclude group: 'com.google.android.google-play-services'
}
compile 'com.google.http-client:google-http-client-gson:1.17.0-rc'
compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude group: 'com.google.android.google-play-services'
}
compile 'com.google.apis:google-api-services-drive:v2-rev105-1.17.0-rc'
}
隨着他們不斷變化,我已經做了一個要點 ,隨着事情的變化,我會不斷更新。
我寫了一篇文章來修改Google雲端硬盤快速入門,使其適用於Android Studio; 如果有興趣,你可以在這里找到它
編輯:此Gradle Imports將使用Google Drive API for Java,而非使用與Google Play服務集成的Developer Preview Google Drive API 。
Java客戶端庫也支持Android。 您可以在此處下載: https : //code.google.com/p/google-api-java-client/wiki/APIs#Drive_API
然后,解壓縮Drive SDK下載並將文件夾移動到項目的libs部分。 例如:/ Users / -username- / AndroidStudioProjects / MyProject / MyProjectActivity / libs /
此時,您可以通過單擊文件 - >項目結構,然后單擊庫選項卡和+符號將庫添加到項目中來將庫添加到項目中。
您可以在此處閱讀Google API客戶端庫for Java的特定於Android的開發說明: https : //code.google.com/p/google-api-java-client/wiki/Android
你試過了嗎
我沒有嘗試谷歌驅動程序,但我嘗試了谷歌USB配件api。 在我的例子中打開MyProject / MyProject / build.gradle
加
compile files("libs/usb.jar")
到依賴塊
當然,復制谷歌驅動程序庫
android-studio\sdk\add-ons\addon-google_apis-google-10\libs\usb.jar
到MyProject / MyProject / libs
祝你好運。
smokybob的回答有效,但后來我做了一些實驗,這對我也有用。
dependencies {
compile files ('libs/libGoogleAnalyticsServices.jar')
compile ('joda-time:joda-time:2.3')
compile ('com.google.code.gson:gson:2.2.4')
compile 'com.google.android.gms:play-services:4.1.+'
}
我猜joda-time和Gson與驅動API無關。
請注意我做的時候
gradle dependancies
我明白了
+--- joda-time:joda-time:2.3
+--- com.google.code.gson:gson:2.2.4
\--- com.google.android.gms:play-services:4.1.+ -> 4.1.32
\--- com.android.support:support-v4:19.0.1
通過SDK管理器下的Extra,我下載了Google Play服務,Google Repository和Android支持庫。 此后,我將依賴項包括在內,與Gradle同步,並能夠訪問API。
依賴項{compile fileTree(dir:'libs',include:['* .jar'])//請參閱。 通過SDK管理器安裝或更新Google Repository以使用此依賴關系。 編譯'com.google.android.gms:play-services:5.0。+'}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.