Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Last active December 22, 2015 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CDRussell/6390501 to your computer and use it in GitHub Desktop.
Save CDRussell/6390501 to your computer and use it in GitHub Desktop.

Maven + Google Play Services

The recently released version of Google Play Services presents itself as a library project with string and attribute resources coupled with a .jar in the libs/ folder that has been compiled against internal APIs.

While this is convenient for users of IDEs or Ant, it presents a problem for those using proper build systems (e.g., Maven, Gradle) with dependency management. Inside the .jar there are a lot of classes which reference static attributes on the com.google.android.gsm.R class. This means that the library must exist in a project which declares that package in its manifest (thus causing aapt to generate an R.java for it). While this makes sense, it presents a problem for users of artifact repositories.

If you use Maven, you can do the following in order to depend on Google Play Services as a library project:

  1. Copy the pom.xml and deploy.sh scripts into the google-play-services_lib/ folder inside of your SDK.
  2. Execute bash deploy.sh which will install the .jar into your local Maven repository.
  3. Run mvn install which will install the Google Play Services as a library project into your local Maven repository.

Once completed you can depend on this library project with the following dependency declaration:

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>google-play-services</artifactId>
  <version>3</version>
  <type>apklib</type>
</dependency>
#!/bin/bash
mvn org.apache.maven.plugins:maven-install-plugin:2.4:install-file \
-DgroupId=com.google.android.gsm \
-DartifactId=google-play-services-jar \
-Dversion=3 \
-Dpackaging=jar \
-Dfile=libs/google-play-services.jar
# To deploy to a remote repository use:
#
# mvn org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file \
# -DgroupId=com.google.android.gsm \
# -DartifactId=google-play-services-jar \
# -Dversion=3 \
# -Dpackaging=jar \
# -Durl=http://example.com/nexus/content/repositories/releases \
# -DrepositoryId=example-nexus \
# -Dfile=libs/google-play-services.jar
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>3</version>
<packaging>apklib</packaging>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android.gsm</groupId>
<artifactId>google-play-services-jar</artifactId>
<version>3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<sdk>
<platform>18</platform>
</sdk>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment