1

In order to try to troubleshoot an issue I'm having trying to create an app targeting Android Pie using Google Maps, 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.

Target Android SDK

  1. Create a very simple layout named activity_main

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)

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

Manifest

<?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.

Timeout exception

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

Working SDK compile

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

Success

  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:

No Class def

  1. Searched online and found that I may need to work around this error by adding the following line to the manifest

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

Timeout exception

  1. If I check the Output, and got this after a Timeout Exceeded exception details

Output

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) :

Article

Workaround

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 ?

I understand that the line I added to the manifest is now mandatory, but still got the timeout exceed exception. It seems that the nuget package for google play services are overdue... Is this the case ?

guyprovost
  • 65
  • 7
  • 2
    You have the `` tag, it needs to be inside the application just like your meta-data tags (in your question example). This is also stated in the answer that you screen cap'd : https://stackoverflow.com/a/50779232/4984832 – SushiHangover Feb 10 '19 at 16:56
  • Doh! Thanks a lot... After all this time! – guyprovost Feb 10 '19 at 19:55
  • I have a huge question here, as it is a bug in Android 9 and above, as it states [here](https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library) why not just target 8.1, i mean why do you specifically want to target 9.0 here? Do you have any such requirements? If you do may be you could tell me why? And may be we could find a better solution – FreakyAli Feb 11 '19 at 06:49
  • Thanks for the input, I've read this article, but the problem is that we are updating an old app done in Xamarin Forms and since we are porting it, I want to actually move it to the most actual platform. This is a client requirement! – guyprovost Feb 13 '19 at 19:19

0 Answers0