Using maps v2 and Google Play Services

228 views
Skip to first unread message

John Cant

unread,
Jul 9, 2015, 1:51:56 PM7/9/15
to clojure...@googlegroups.com
Hello!

I'm trying to set up a MapView inside a clojure android app.

I followed the instructions here to add the google play services - https://github.com/clojure-android/lein-droid/issues/87 and I can now import and instantiate classes and call methods without borkage at them not being present. However, I'm getting some errors which culminate in a java.lang.NullPointerException from deep within google maps when I try to use the MapView. I've already spent 2 days trying to fix it with no success yet, which brings me here.

Here's my attempt so far: https://github.com/johncant/cljmapdemo
Here is its output: http://pastebin.com/rdwuapXC

Here is my /opt/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/project.clj : http://pastebin.com/p6DxCA3n

Possible causes from the log:

  1. I/dalvikvm(22467): Could not find method java.beans.Introspector.getBeanInfo, referenced from method clojure.core$bean.invoke
  2. W/dalvikvm(22467): VFY: unable to resolve static method 51582: Ljava/beans/Introspector;.getBeanInfo (Ljava/lang/Class;)Ljava/beans/BeanInfo;
  3. D/dalvikvm(22467): VFY: replacing opcode 0x71 at 0x002f
Ignored this error message because the app still functions afterwards

  1. E/MoreInfoHPW_ViewGroup(22467): Parent view is not a TextView

Supposedly just a known issue with Samsung phones, which I can ignore

  1. E/dalvikvm(22467): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
  2. W/dalvikvm(22467): VFY: unable to resolve check-cast 25 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;

Apparently this means my API key probably isn't working. I sort of expect this at this stage, but not the carnage that follows:

  1. W/dalvikvm(22467): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
  2. W/dalvikvm(22467): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
  3. W/dalvikvm(22467): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
  4. W/dalvikvm(22467): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
  5. E/dalvikvm(22467): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
  6. W/dalvikvm(22467): VFY: unable to resolve instanceof 181 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;

Guessing that google maps is trying to show an error dialog, but crashing because it can't find the android support libraries.

I've tried just about every combination of lein options in my project.clj and google play services' project.clj and I can't resolve this error. However, I can import classes from android support libraries without the app breaking immediately or failing to compile.

  1. E/GooglePlayServicesUtil(22467): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

Looks like the most promising error so far - The stack overflow answers are kind of useless though, suggesting IDE-specific fixes, or that it's because of a bug in google play services and should be ignored. I tried adding :resource-paths ["res"] to the google play services project.clj and doing lein clean, but this didn't work.

  1. I/Google Maps Android API(22467): Google Play services client version: 7571000
  2. I/Google Maps Android API(22467): Google Play services package version: 7574034

OK, so my google play services is different in the SDK than it is on my phone. I couldn't find a way of getting google play services V 7.5.74-034 as a jar for use with the sdk. Anyway, a change in minor version shouldn't completely break an app, or all apps would be broken most of the time.

Then the NPE. There don't seem to be many helpful answers out there for that either.

Does anyone have any idea what the problem might be?
Has anyone got an example maps application up and running with lein-droid?
What should I try next?

Thankyou for your help.






Alexander Yakushev

unread,
Jul 9, 2015, 2:09:00 PM7/9/15
to clojure...@googlegroups.com, a.joh...@gmail.com
Hello John,

I'm traveling atm so I can't look into your issue properly. But from what you describe and if it is really a resource issue, I think the :project-resources doesn't work. You can still import classes because you get them from the JAR you add with external-classes-paths.

Someone certainly managed to include Google Maps but I haven't. I can check it when I get back home.

Adam Clements

unread,
Jul 10, 2015, 10:24:36 AM7/10/15
to clojure...@googlegroups.com, a.joh...@gmail.com

I'm having similar issues importing play services to use the analytics. Importing the android bundled extras is a bit of a pain at the moment, there seem to be a lot of different ways of doing it, none of which works particularly well. I particularly dislike having to set hard paths for the dependencies. I think a lot of this would get easier with AAR support,  at which point I think you could bundle the play services into an AAR, but this requires someone to get around to that!

It's also a bit rubbish that the resource path is a string rather than a vector at the moment, that  would have allowed for a temporary workaround at least.

Adam.


--
You received this message because you are subscribed to the Google Groups "clojure-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-andro...@googlegroups.com.
To post to this group, send email to clojure...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-android.
For more options, visit https://groups.google.com/d/optout.

Alexander Yakushev

unread,
Jul 26, 2015, 5:14:00 AM7/26/15
to clojure-android, a.joh...@gmail.com, a.joh...@gmail.com
Dear John,

Latest lein-droid adds support for AAR packages. Now you can add Google Play Services properly: http://clojure-android.info/blog/2015/07/26/leindroid-update-aar-support/

Best regards,
Alex

John Cant

unread,
Jul 27, 2015, 6:59:15 PM7/27/15
to clojure-android, al...@bytopia.org
This is awesome! I'll get my demo working. Thankyou very much for your help!

Răzvan Rotaru

unread,
Aug 10, 2015, 4:19:58 PM8/10/15
to clojure-android, a.joh...@gmail.com
Hi,

I am having similar problems. Here are my steps:
- create new project using "lein new droid <project-name> <package>".
- change :sdk-path to correct path
- run "lein droid doall"

So far, no problems, the app is successfully deployed on my simulator and started.

Now add following dependency:
    [com.google.android.gms/play-services-maps "7.5.0" :extension "aar"]

Running "lein droid doall" ends up in a crash on the mobile simulator. The cause is a NullPointerException, but I did not manage to get the whole stack trace.

The strange part is that after surrounding the code at SplashActivity.setupSplash() in a try catch, everything works fine (no exception thrown at all), but the maps library still seems unavailable (i.e. the class
com.google.android.gms.maps.MapFragment does not exist).

R.


Alexander Yakushev

unread,
Aug 10, 2015, 4:26:46 PM8/10/15
to clojure-android, a.joh...@gmail.com
Hello Răzvan,

Why do say you couldn't get the stacktrace? What does `adb logcat` show at the moment of crash?

Răzvan Rotaru

unread,
Aug 11, 2015, 2:04:09 PM8/11/15
to clojure-android, a.joh...@gmail.com
I did some more digging today, and found out that it is not related to google maps, but rather with how the app is deployed.

Here is what logcat shows:

08-11 13:43:04.013: E/lookingForErrorCause(2271): appNameView = null, R.string.app_name = 2131034146
08-11 13:43:04.023: E/AndroidRuntime(2271): FATAL EXCEPTION: main
08-11 13:43:04.023: E/AndroidRuntime(2271): Process: com.example.debug, PID: 2271
08-11 13:43:04.023: E/AndroidRuntime(2271): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.debug/com.example.SplashActivity}: java.lang.NullPointerException
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.os.Looper.loop(Looper.java:136)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread.main(ActivityThread.java:5001)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at java.lang.reflect.Method.invokeNative(Native Method)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at java.lang.reflect.Method.invoke(Method.java:515)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at dalvik.system.NativeStart.main(Native Method)
08-11 13:43:04.023: E/AndroidRuntime(2271): Caused by: java.lang.NullPointerException
08-11 13:43:04.023: E/AndroidRuntime(2271):     at com.example.SplashActivity.setupSplash(SplashActivity.java:41)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at com.example.SplashActivity.onCreate(SplashActivity.java:24)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.Activity.performCreate(Activity.java:5231)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-11 13:43:04.023: E/AndroidRuntime(2271):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
08-11 13:43:04.023: E/AndroidRuntime(2271):     ... 11 more


The first line is caused by a line of code added by me, to find out who is null, so in the original SplashActivity.java file, the error occurs at line 41.
The error seems to happen when I run "lein droid doall" and the app is already installed, although it did not occur every time. Anyway, here's a way to reproduce the error:
  • create new project with the lein-droid template ("lein new droid com.example")
  • set sdk-path in project.clj and run "lein droid doall": everything should work fine
    • leave the application running in android
  • add following dependency to project.clj:
    • [com.google.android.gms/play-services-maps "7.5.0" :extension "aar"]
  • run "lein droid doall" - now the app crashes
  • if for some reason the app does not crash anymore, removing the dependency to play-services-maps and running "lein droid doal" again should cause it to crash again

This looks like a bug in lein-droid, doesn't it?


Răzvan




Răzvan Rotaru

unread,
Aug 11, 2015, 2:51:46 PM8/11/15
to clojure-android, a.joh...@gmail.com
Note: exception occurs at SplashActivity.java:40,  not 41 like I wrote.

I also found out that, if the app keeps crashing, running a "lein clean" before "lein droid doall" makes the problems go away (until next time, when you have to clean again ☺ ).

So, it's a DEX thing I guess.

Adam Clements

unread,
Aug 11, 2015, 5:20:09 PM8/11/15
to clojure-android, a.joh...@gmail.com

Just a guess here but this sounds like it might be a multi dex issue. You add the extra dependency and it becomes random which of the multiple dex files your splash activity gets bundled into. Then when code tries to resolve your splash activity through reflection, instead of a class not found, it looks like a null pointer error?

See if in the cases where it fails you have both a classes.dex and a classes2.dex in your target directory, and if that's true, use the dex dump tool and grep to see which one has your splash activity in it. If it's not in the first one, that's not available straight away and you need to set the main dex class rules proguard file, I think there are instructions in the wiki. I can't remember offhand and am on my phone.

Let me know if it looks like this is the issue but you're still having trouble.

Adam


--

Răzvan Rotaru

unread,
Aug 18, 2015, 3:38:29 PM8/18/15
to clojure-android, a.joh...@gmail.com
So, after changing project.clj, running "droid doall" and the app is crashing, I have only one classes.dex file:

roti@pella:~/proiecte/test$ find . -name *.dex
./target/debug/classes.dex

SplashActivity is definitely there (I checked with "dexdump -d classes.dex | grep SplashActivity").


Razvan

Reply all
Reply to author
Forward
0 new messages