Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use google play services in a maven project?

Somebody can give me a step by step tutorial about how can I use google play services in a maven project? I've added two dependencies

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>4</version>
    <type>apklib</type>
</dependency>

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>4</version>
    <type>jar</type>
</dependency> 

The apklib and jar appear in maven repository but the com.google.android.gms.R class is not generated.

I receive NoClassDefFoundError. How can I put the com.google.android.gms in the gen folder?

like image 254
user2294317 Avatar asked Jul 05 '13 10:07

user2294317


2 Answers

You can use the Android Maven SDK Deployer for more than just Google Play Services

".apklib" with android-maven-plugin <3.8.1

Btw you should use version 13.0.0 and not 4

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>google-play-services</artifactId>
  <version>13.0.0</version>
  <type>apklib</type>
</dependency>

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>google-play-services</artifactId>
  <version>13.0.0</version>
</dependency>

".aar" with android-maven-plugin 3.8.2+

With android-maven-plugin 3.8.2 you can also use the play services aar

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>play-services</artifactId>
  <version>4.0.30</version>
  <type>aar</type>
</dependency>
like image 97
Benoit Avatar answered Oct 18 '22 20:10

Benoit


After importing the google-play-services_lib project into your Eclipse workspace and making it a library you need to setup the maven build process.

Make a zip file of the "google-play-services_lib" folder and call it "google-play-services_lib.apklib"

  + google-play-services_lib.apklib
     + src
     + res
     + AndroidManifest.xml
     + project.properties

Open the command prompt and go to the folder where the zip file is and type the following command. This will install the apklib into you local maven repository.

mvn install:install-file -Dfile=google-play-services_lib.apklib -DgroupId=com.google.android.gms -DartifactId=google-play-services -Dversion=14.0.0 -Dpackaging=apklib

Now you need to install the google-play-services jar into your local repository.

mvn install:install-file -Dfile=google-play-services.jar -DgroupId=com.google.android.gms -DartifactId=google-play-services -Dversion=14.0.0 -Dpackaging=jar

Go back into Eclipse and open your android pom file and enter the following dependency

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>google-play-services</artifactId>
  <version>14.0.0</version>
  <type>apklib</type>
</dependency>    

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>google-play-services</artifactId>
  <version>14.0.0</version>
</dependency>

Now you can run your maven package command to have output update with the google play jar and the apklib merged into your apk file.

mvn package -Pandroid -Psign

like image 25
Kyght Avatar answered Oct 18 '22 19:10

Kyght