Google Maps Apps targeting Android Pie are broken ?

GuyProvostGuyProvost CAMember ✭✭✭

In order to try to troubleshoot the issue I'm having trying to create an app targeting Android Pie, I've decided to start a very small project to target and isolate what may be the problem I'm having, here's what I got...

  1. Create a new Android project targeting Android Pie, updated the support design library (Xamarin.Android.Support.Design) to 28.0.0.1 because by default the template seems to set the target at 8.1. I then added the the nuget package "Xamarin.GooglePlayServices.Maps". Which generated a warning about a dependencie not beign updated (Xamarin.Android.Support.Media.Compat) and still at 26.0.2. So I manually update it at 28.0.0.1.

  1. Create a very simple layout named activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_marginTop="24dp" />
</LinearLayout>

Which is only a linear layout containing a single google maps fragment

  1. Create the activity class (MainActivity.cs)
namespace SimpleMapTest
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
        }
    }
}

Which only set the content view defined in the layout file

  1. Adding the required lines in the manifest for my Google Maps API key
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="SimpleMapTest.SimpleMapTest">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
    <uses-library android:name="org.apache.http.legacy" android:required="false"/>
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="[MyKeyValue]" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>
</manifest>

  1. Compile the app. The app deployed ok, started, but when the map is about to be shown, I got this error.

  1. Then, without changing a single line, went to the project property screen and changed to compile against Android Oreo (8.1)

  1. Compile the thing, deploy and run the app, the app worked successfully

  1. Got back to the project property, change the target back to Android Pie (9.0) and recompile and deploy. App compiles, deploy and start running, but this time the exceptionI got at runtime was this one:

  1. Searched online and found that I may need to work around this error by adding the foillowing line to the manifest
<uses-library android:name="org.apache.http.legacy" android:required="false" />

I guess it should be something about Android 9 changing the way it handles HTTP request

  1. I've added the line in the manifest, recompile, deploys and at runtime got back the same exception I got the first time, concerning a timeout

  1. If I check the Output, I got this after the Timeout Exceeded exception
02-10 10:50:48.352 W/t.SimpleMapTes(28585): Unsupported class loader
02-10 10:50:48.358 W/t.SimpleMapTes(28585): Skipping duplicate class check due to unsupported classloader
02-10 10:50:49.082 E/AndroidRuntime(28585): FATAL EXCEPTION: Thread-6
02-10 10:50:49.082 E/AndroidRuntime(28585): Process: SimpleMapTest.SimpleMapTest, PID: 28585
02-10 10:50:49.082 E/AndroidRuntime(28585): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

Which seems to indication that the workaround detailed in step 9 is no longer a way to go, which fits with this article (first response) : https://stackoverflow.com/questions/50461881/java-lang-noclassdeffounderrorfailed-resolution-of-lorg-apache-http-protocolve

So kinda back at square one!

So whay should be the proper way to build an app targeting Android Pie that uses Google Maps in a fragment ? I'm lost here! Anyone can share an explanation that may be usefull to all ?

Sign In or Register to comment.