使用 Android Studio 让 Google Play Services 运行的解决方案似乎并不缺乏。我已经尝试过其中的大多数。经过多次试验和多次错误后,我得出的结论是,为了使这些解决方案中的许多解决方案发挥作用,您必须像这些解决方案的作者一样拥有准确的版本组合。这种神奇的组合似乎对您使用任何给定解决方案的成功程度都有非常实际的影响。我相信我还没有找到我正在使用的软件版本的解决方案,但不排除我错过了一些简单/愚蠢的东西的可能性,所以请温柔点。
这是我的设置,希望有人能够看到这个问题:
我总是从头开始。这样我就知道旧版本中没有任何挥之不去的污泥会困扰我。我正在使用 Android Studio(预览)0.4.2、gradle 0.7(每个 build.gradle 文件),并尝试使用 Google Play Services 4.0.30,以便我可以使用 Google Maps V2。
我已打开 SDK 管理器并下载了每个更新,并验证我已加载所有 SDK 工具、所有 API 19(以及加载的许多较低版本,包括 14)以及加载的所有附加内容,包括支持存储库、支持图书馆和 Google Play 服务。基本上我在过度下载方面犯了错误。
通过此配置,我可以:
import com.google.android.gms.*
但没有 .maps 或其他任何东西,所以没有 GoogleMap 等。
我将展示一些关键文件的内容。很抱歉篇幅较长,但可能有一些东西隐藏在我意想不到的地方,我不想“不显示”这个问题。所以请耐心听我说。 ...如果有人需要查看更多内容,请也告诉我。谢谢
我的构建.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services:4.0.30'
// Support Libraries
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:support-v13:19.0.0'
}
我的 proguard-rules.txt:
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
# Keep SafeParcelable value, needed for reflection. This is reqd to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
# Keep the names of classes/members we need for client functionality.
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
# Needed for Parcelable/SafeParcelable Creators to not get stripped
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
我的 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.klhsoftware.k4wmapp" >
<permission
android:name="com.klhsoftware.k4wmapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.klhsoftware.k4wmapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true">
<activity
android:name="com.klhsoftware.k4wmapp.MapScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="LocationsContentProvider"
android:authorities="in.wptrafficanalyzer.locationmarkersqlite.locations"
android:exported="false" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza<myValue>-tsldkfjdOM" />
</application>
</manifest>