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 ?

Posts

  • MarkHeinisMarkHeinis USMember ✭✭

    I think that the workaround still works, just put the use-library within the application tag

  • ElteHupkesElteHupkes USMember ✭✭

    For what it's worth, the workaround works for me. The <uses-library ... /> tag is the last one on my <application /> tag.

    Can't we update play-services-maps somehow? I can't even find out what version Xamarin.GooglePlayServices.Maps includes for you..

  • wallymwallym USInsider, Beta ✭✭✭

    I have implemented the change. Now I get an error that for google maps to work, I must provide the fine_location and course_location permission. The problem is that I do. Here is the content of my AndroidManifest.xml below. I always assume the problem is with me. Does anything look out of whack? I'm just not sure what I am missing.

    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:label="PooperAppMobile.Android">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="******" />
        <uses-library
          android:name="org.apache.http.legacy"
          android:required="false" />
    </application>
    

    My android OnCreate is shown below.

    protected override void OnCreate(Bundle savedInstanceState)
    {
    Instance = this;

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
    
            base.OnCreate(savedInstanceState);
    
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.FormsMaps.Init(this, savedInstanceState);
            LoadApplication(new PooperAppMobile.App());
        }
    
  • wallymwallym USInsider, Beta ✭✭✭

    ugh, I hate it when I ask a question, then realize what I was doing wrong. I refer to this as poster's remorse. I'm good now. Try not to laugh too much.

  • XamarinProblemsXamarinProblems Member ✭✭

    @GuyProvost just ran into this issue, luckily the workaround you mentioned worked for me, thanks for the detailed post. I hope they get it fixed or update the plugin to manage this better.

  • anderson_Smauganderson_Smaug Member ✭✭

    Goes in android / android / httpClint project options and puts managed (HttpClientHandler)
    another tag in android Manifast

  • harrys_utilsharrys_utils Member ✭✭
    edited July 12
    Adding the tagline in the manifest worked great for me. I was really stuck. Just remember to put the line within the application tag usually found at the bottom of the manifest xml file. What a obscure fix to a obscure problem. I had suddenly discovered that my app wasn't working on the new Pixel 3A's.my app was working on older models of phone running pie but not on new models running pie. I cannot thank the original poster enough for helping me fix this issue. thank you, thank you, thank you. Posted July 11th 2019.
  • harrys_utilsharrys_utils Member ✭✭
    I found it only worked great when you deploy to the phone directly. uploading to the Google play store and then running the app will cause it to crash instantly.
  • LuiginoDeTogniLuiginoDeTogni USMember ✭✭

    @MarkHeinis said:
    I think that the workaround still works, just put the use-library within the application tag

    I confirm, that workaround still works

Sign In or Register to comment.