2

There doesn't seem to be a shortage of solutions available for getting Google Play Services to work using Android Studio. I’ve tried most of them. After much trial and much error I’ve come to the conclusion that in order for many of these solutions to work you must have the exact combinations of versions as the authors of these solutions. This magic combination seems to have a very real effect on how successful you will be with any given solution. I believe that I have not found the solution for the versions of software that I am using, but haven’t ruled out the chance I have missed something simple/stupid so please be gentle.

So here is my setup and hopefully someone will be able to see the problem: I always start from scratch. That way I know I don’t have any lingering sludge from an older version that would mess with me. I am using Android Studio (Preview) 0.4.2, gradle 0.7 (per build.gradle file), and am trying to use Google Play Services 4.0.30 so that I can use Google Maps V2.

I have opened the SDK Manager and have downloaded every update and verified that I have all the SDK tools loaded, all of API 19 loaded (and many of the lower versions loaded including 14, and all of the Extras loaded including the Support Repository, Support Library, and Google Play Services. Basically I’ve erred on the side of over-downloading.

With this configuration I can:

import  com.google.android.gms.*

but no .maps or anything else so no GoogleMap etc.

I’ll show the contents of some key files. Sorry for the length but there may be something hiding in a place I wouldn’t expect and I wouldn’t want to ‘not show’ the problem. So please bear with me. ...And if someone needs to see more please let me know too. Thx

My 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'
}

My 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;
}

My 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>
K4 Nerd
  • 157
  • 3
  • 8
  • So the problem is the autocompletion in the IDE doesn't work? Can you run through the list of steps in the question and answer to this and see if it helps? There are some Android Studio bugs we're trying to pin down and fix. http://stackoverflow.com/questions/21100688/android-studio-0-4-2-suddenly-cannot-resolve-symbols – Scott Barta Jan 13 '14 at 23:09
  • Per your link: -Rebuild the project -> nothing Gradlew clean -> made my ‘R’ in setContentView(R.layout.xxxx… not resolved (red) -Syncing Gradle Files -> made the ‘R’ come back (took it a sec tho) -Closing AS / reopening -> no change -File > Invalidate Caches / restart -> no change -Lint -> skipped -Double chk support libs -> SDKs & APIs for every version back to 2.3 – absolutely everything else loaded & current. -build.gradle is per my post – K4 Nerd Jan 13 '14 at 23:57
  • However your answer per your link WORKED! – K4 Nerd Jan 13 '14 at 23:57
  • Okay, I'll post that as an answer to the question. – Scott Barta Jan 13 '14 at 23:58
  • This works: http://stackoverflow.com/questions/21100688/android-studio-0-4-2-suddenly-cannot-resolve-symbols – K4 Nerd Jan 13 '14 at 23:58
  • @K4Nerd Question, why are you still using com.android.tools.build:gradle:0.7.+ instead of com.android.tools.build:gradle:0.8.+? – IgorGanapolsky Feb 05 '14 at 16:28

2 Answers2

2

We've been seeing problems with newly added libraries not getting properly picked up; I think this is bug https://code.google.com/p/android/issues/detail?id=64508 which will be fixed in 0.4.3. In the meantime,

  • Exit Android Studio
  • Back up your project
  • Delete all the .iml files and the .idea folder
  • Relaunch Android Studio and reimport your project

This is the same answer as Android Studio suddenly cannot resolve symbols

Community
  • 1
  • 1
Scott Barta
  • 79,344
  • 24
  • 180
  • 163
1

I don't see GooglePlayServices version specified in your manifest via meta-data attribute:

<meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />

Please see set-up guidelines

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83