4

Sorry for adding just another "android maven google maps dependency not found" question, but I think that I have read most of the posts about it and applied all the proposed solutions with no success.

I have a maven Android project running OK with Google Maps V2 dependency that is not referenced using maven but via google-play-services_lib project imported in workspace and eclipse build path library dependency.

Now I am trying to configure the google-play-services dependency via pom, as I am implementing maven automated tests with Robolectric, but I am stuck with this error showing in first line of pom, with no quick-fix:

dependency=[com.google.android.gms:google-play-services:apklib:7:compile] not found in workspace

What I have tried so far, after lots of googling, and checking results after each step without success:

  • Initially installed google play services components to my local .m2 repository with android-maven-sdk-helper (following these instructions), and add to project pom two dependencies to jar and apklib version 7, which is my locally installed version (like here). After this it was supposed to work but the dependency error appeared.

  • Remove from eclipse build path the reference to library google-play-services_lib (in project / preferences / Android / Libraries). Anyway, google-play-services_lib project is still in the workspace.

  • Copy apklib from my local m2 repository into some place in workspace: I tried google-play-services_lib/bin, google-play-services_lib/libs, MyProject/libs. Tested using name google-play-services-7.apklib (as in repository file) and google-play-services.apklib.

  • "Mavenise" the google-play-services_lib project included in the workspace, by running eclipse Configure / Convert to Maven project. I edited the generated pom to update packaging type to apklib: <packaging>apklib</packaging>, and added android-maven-plugin with <extensions>true</extensions> in order to recognize the apklib package type. I compiled the project with maven goal compile, with success, but I can not find the generated apklib file anywhere.

After each of these changes I do Maven / Update project, clean project, even restart Eclipse. No success: the dependency not found in space error is still there.

I don't know what else to try. Could it be something with the library name? The library project name is google.play-services_lib, with _lib suffix, and the jar referenced in eclipse android library build path is the _lib.jar, but the maven artifacts do not have the _lib suffix. I have also tried some renaming in the components and artifacts with no success, but I guess the problem could be there. Could someone post an example pom.xml for the mavenised google-play-services_lib project?

Another guess: when I mvn compile the mavenised library project, why can't I find the generated .apklib file, where is it? I checked the trace with mvn -X compile and didn't find any hint.

Environment and versions:

Eclipse Indigo
External maven 3.0.5 (embedded Maven 3.0.3 not used)
android-maven-plugin 3.6.0
maven-eclipse-plugin 2.8
m2e-android plugin (m2eclipse android integration) 0.4.2
Android API level 13

The pom.xml I added to google-play-services_lib project:

<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>google-play-services_lib</groupId>
<artifactId>google-play-services_lib</artifactId>
<version>7</version>
<packaging>apklib</packaging>

<properties>
    <android-platform>13</android-platform>
    <android-emulator>13</android-emulator>
    <android-maven-plugin-version>3.6.0</android-maven-plugin-version>
    <maven-compiler-plugin-version>3.0</maven-compiler-plugin-version>
    <java-version>1.6</java-version>
    <local-sdk-path>C:\NoProgramFiles\Android\android-sdk</local-sdk-path>
</properties>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>${android-maven-plugin-version}</version>
            <configuration>
                <sdk>
                    <path>${local-sdk-path}</path>
                    <platform>${android-platform}</platform>
                </sdk>
                <emulator>
                    <avd>${android-emulator}</avd>
                </emulator>
                <deleteConflictingFiles>true</deleteConflictingFiles>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
            </configuration>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin-version}</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Community
  • 1
  • 1
Diana
  • 2,186
  • 1
  • 20
  • 31
  • just get a lib like that – Giant Jul 04 '13 at 08:14
  • 1
    Last time I checked the m2e-android plugin it was not supporting the apklib depedencies, so this could explain your issue. Do they have implemented it recently? – rciovati Jul 04 '13 at 10:09
  • @rciovati, this could be the point: there is a m2e-android issue reported about this feature and I checked that the issue was closed, but I didn't notice the fixing version: 0.4.3 Beta 4. My current m2e-android plugin version is 0.4.2, so I will give it a try and let you know. Thanks! The issue report: [link](https://github.com/rgladwell/m2e-android/issues/8) – Diana Jul 04 '13 at 10:40
  • @Satine sorry, this is not valid. This lib can't be added just putting the dependency in the pom, as it is an android library with its own resources. – Diana Jul 04 '13 at 11:42
  • @Diana let me know :) Or this could be the right time for switch to Android Studio (or IntelliJ) which support out of the box apklibs. – rciovati Jul 04 '13 at 12:03
  • @rciovati Nope, I tested with m2e-android 0.4.3 (installed by adding to eclipse repository http://rgladwell.github.com/m2e-android/updates/master and updating). Same error. I tested same different things than in the question post. So I guess the error is in my configuration. – Diana Jul 05 '13 at 09:48
  • @rciovati, I found the solution, please check my answer. The problem was not the m2e-android plugin, but some errors in my configuration and lib package generation. – Diana Sep 07 '13 at 12:02

2 Answers2

1

Finally the problem was about artifacts naming and apklib not being generated in the apk library project. This is what was wrong:

  • The groupId and artifactId in the library pom were wrong: they must fit the name specified in the error message (I should have read it more carefully).

The right values:

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

Instead of the ones generated by eclipse when converting the project to maven, which were based on the project name:

<groupId>google-play-services_lib</groupId>
<artifactId>google-play-services_lib</artifactId>
  • The apklib is not generated with mvn compile, the right instruction for that is mvn package. This way the apklib file gets generated in target folder of the project library.

So m2e-android 0.4.2 supports apklib dependency with mavenised google-play-services apklib, although the library project still has to be included in the workspace.

Final note: I got run time errors when running the maps activities in the real device:

07-08 09:42:45.170: W/dalvikvm(27953): VFY: unable to resolve virtual method 4296: Lcom/google/android/gms/maps/GoogleMap;.setMapType (I)V
07-08 09:42:45.180: E/dalvikvm(27953): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method mypackage.MyMapActivity.setUpMapIfNeeded
07-08 09:42:45.180: W/dalvikvm(27953): VFY: unable to resolve check-cast 801 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lmyapp/MyMapActivity;
07-08 09:42:45.180: E/dalvikvm(27953): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method mypackage.MyMapActivity.onCreate
07-08 09:42:45.200: E/AndroidRuntime(27953): java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage/mypackage.MyMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

It seems that the maps library was not included in the app apk. My fix: in google-play_services_lib project eclipse Properties / Java Build Path / Order and Export tab I checked the Android Private Libraries checkbox, so the original google maps jar is installed in the running device.

Diana
  • 2,186
  • 1
  • 20
  • 31
1

If problem persist with naming mismatch resolved (same name in library pom and project pom), after updating maven project (project explorer, right click any project->maven->update maven project) try just deleting that message (!!).

I problem tab, right-click error message and select 'Delete'. Worked for me and for Kevin Peck- Eclipse dependency not found in workspace fix

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
  • 1
    Thanks for the link, I didn't know that errors could get 'stuck' in eclipse. Good to know they can be removed this way. – Diana Oct 07 '14 at 11:04