Android + Google Play Services

Hello there,
I am trying to create a simple app that makes use of the Google Maps API v2. Basically how it is described in the official guide: https://developers.google.com/maps/documentation/android/start
This is fairly simple using Eclipse and took me about 20 minutes, when considering some further setup options as for example described here: http://wptrafficanalyzer.in/blog/google-maps-in-android-application-with-new-google-maps-android-api-v2-using-supportmapfragment/

However, it seems impossible to me to add the "google-play-service_lib" project as an dependency to IntelliJ as it is described for Eclipse. Instead I added the jars (Google Play Services and the Android Support Package) as two module dependencies to my main IntelliJ module what I also found the cleaner solution. The compiler will not complain about this, however whenever I start the very same app as I wrote before using Eclipse, the app will crash imediately with IntelliJ. The stack trace tells me:

java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
...
at com.example.maptest.MainActivity.onCreate(MainActivity.java:11)

When not adding the libraries I get (as expected):

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment

since the Google Play Service Classes are simply missing. If I import the google-play-service_lib SDK project as a module, the same thing happens.
If I however add the entire SDK project folder (google-play-service_lib) as a module dependency I get:

Android Dex: [maptest] UNEXPECTED TOP-LEVEL EXCEPTION:
Android Dex: [maptest] java.lang.IllegalArgumentException: already added: Landroid/UnusedStub;

what does not really tell me anything

I am using SDK version 16 (4.1.2) to build my app and test on a Sony Xperia Z. I am using Intellij CE 12. As I said, everything worked with Eclipse (which I do not want to use).
Any ideas? Thank you guys so much! I also attached the sample project to this thread.



Attachment(s):
maptest.zip
1 comment

Nevermind. This solved my problem:

  1. Create a file
    ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/src/dummy.java
    containing
    class dummy {}
    .
  2. File->Import Module->
    ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib
  3. Create Module from Existing Sources
  4. Next->Next->Next->Next->Finish
  5. File->Project Structure->Modules->YourApp
  6. +->Module Dependency->Google-play-services_lib  (The + button is in the top right corner of the dialog.)
  7. +->Jars or directories->
    ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
  8. Use the up/down arrows to move
    <Module source>
    to the bottom of the list.
0

Please sign in to leave a comment.