【发布时间】:2014-02-01 21:35:39
【问题描述】:
似乎并不缺少可用于让 Google Play 服务使用 Android Studio 工作的解决方案。我已经尝试了其中的大部分。经过多次尝试和多次错误,我得出的结论是,为了使这些解决方案中的许多工作正常,您必须拥有作为这些解决方案的作者的版本的精确组合。这种神奇的组合似乎对任何给定解决方案的成功程度都有非常实际的影响。我相信我没有找到我正在使用的软件版本的解决方案,但不排除我错过了一些简单/愚蠢的事情的机会,所以请温柔。
所以这是我的设置,希望有人能够看到问题: 我总是从头开始。这样我就知道我没有旧版本的任何挥之不去的污泥会弄乱我。我正在使用 Android Studio (Preview) 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 等。
我将展示一些关键文件的内容。抱歉,篇幅较长,但可能有一些东西隐藏在我没想到的地方,我不想“不显示”这个问题。所以请多多包涵。 ...如果有人需要查看更多内容,请也告诉我。谢谢
我的 build.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>
【问题讨论】:
-
那么问题是IDE中的自动完成功能不起作用?你能浏览一下问题和答案中的步骤列表,看看它是否有帮助?我们正在尝试确定和修复一些 Android Studio 错误。 stackoverflow.com/questions/21100688/…
-
根据您的链接: - 重建项目 -> 没有清理 Gradlew -> 在 setContentView(R.layout.xxxx... 未解决 (红色) - 同步 Gradle 文件 -> 制作了我的“R” 'R' 回来(花了一秒钟) - 关闭 AS / 重新打开 -> 没有变化 - 文件 > 使缓存无效 / 重新启动 -> 没有变化 -Lint -> 跳过 -Double chk 支持库 -> 每个版本的 SDK 和 API回到 2.3 - 绝对所有其他内容都已加载和当前。-build.gradle 是根据我的帖子
-
但是您的链接的回答有效!
-
好的,我会把它作为问题的答案发布。
标签: android google-maps gradle android-studio google-play-services