1

Whenever I return (onResume) to my only activity, my app crashes with the below error. My Activity contains only a Google Map and a banner ad (from Facebook Audience Network)

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 14320 (RenderThread), pid 14265

How can I fix this issue? I would appreciate your help on this. I could not find the problem as my code is very simple.

Here's my activity_maps.xml:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/constraintLayout"
    tools:context=".MapsActivity">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity" />

    <LinearLayout
        android:id="@+id/banner_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

Here's my MapsActivity.java:

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;
import android.widget.LinearLayout;
import com.facebook.ads.AdSize;
import com.facebook.ads.AdView;
import com.facebook.ads.AudienceNetworkAds;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private AdView adView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        AudienceNetworkAds.initialize(this);

        adView = new AdView(this, "my_placement_id", AdSize.BANNER_HEIGHT_50);

        // Find the Ad Container
        LinearLayout adContainer = findViewById(R.id.banner_container);

        // Add the ad view to your activity layout
        adContainer.addView(adView);

        // Request an ad
        adView.loadAd();
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
    }
}

Here's how it looks like:

enter image description here

Adam
  • 89
  • 5
  • Does this https://www.simplifiedcoding.net/how-to-search-location-in-google-map-in-android/ answers your question? – Nemanja Aug 21 '20 at 11:31
  • Could you share the details of error message? Such DEBUG information, like the **UPDATE** paragraph of [this question](https://stackoverflow.com/q/17840521/9298629), often contains clues to find out where crashes take place in native libraries. – qtmfld Sep 05 '20 at 07:00
  • On a side note, it looks like you are putting the ad banner above Google Maps Platform attributes (logo, copyrights, etc). Please note that this might be in violation of Google Maps Terms of Service particularly in item 3.2.2 (b) Attribution: https://cloud.google.com/maps-platform/terms/#3.-license. – jabamataro Sep 09 '20 at 09:07

4 Answers4

0

In the Logcat message:

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 14320 (RenderThread), pid 14265
  • A/libc shows that the priority is A (Assert) and the tag is libc (bionic).
  • The message is Fatal signal 11 (SIGSEGV), which means that your app terminates itself, receiving a signal of segmentation violation.
  • code 1 (SEGV_MAPERR), fault addr 0x0 details that libc failed to read or write memory address 0x0 (null pointer), as explained in this answer.
  • The rest in tid 14320 (RenderThread), pid 14265 shows that this crash took place in thread 14320 (RenderThread) of process 14265.

RenderThread indicates that this might be due to hardware acceleration.

To turn off the acceleration, add an attribute

android:hardwareAccelerated="false"

to one of these elements in AndroidManifest.xml.

I think it's worth a try.

qtmfld
  • 2,916
  • 2
  • 21
  • 36
0

You Mixed up some things!

Have a look at the Facebook Documentation under: initialize-the-audience-network-sdk

You can see that they call AudienceNetworkAds.initialize(this); in the Application class and not in the Activity.

Create a Class like in the documentation:

public class YourApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the Audience Network SDK
        AudienceNetworkAds.initialize(this);       
    }

}

The next Step is to add the class with android:name=".YourApplication" in the Manifest file, like in the example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.rieger.com.myapplication">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:name=".YourApplication"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

This tells Android where he can find your implementation of the Application class.

Then remove the AudienceNetworkAds.initialize(this); line from your onCreate() Method in the class MapsActivity.

Now everything should work well.

Why does the exception show up?

Have a look at the Activity Lifecycle.

Activity Lifecycle

onCreate() can be called by the system at every startup of your Activity and not only onResume() or onStart().

What happens is that the emulator call onCreate() when you open the Activity for the second time over the onCreate() method. Which leads to a second call of AudienceNetworkAds.initialize(this); which causes the error.

Another hint

Don't forget to implement the onDestroy() method like:

@Override
protected void onDestroy() {
    if (adView != null) {
        adView.destroy();
    }
    super.onDestroy();
}
Sebastian Rieger
  • 685
  • 5
  • 20
  • Apart from that it isn't necessary and causes overhead, what is the issue with initializing multiple times? A memory leak? – nulldroid Sep 07 '20 at 15:53
  • @nulldroid as you can read under https://developers.facebook.com/docs/audience-network/reference/android/com/facebook/ads/audiencenetworkads.html/ you should initialize the SDK as soon as possible. Yes, you can call initialize() in the onCreate() Method of an Activity but only if you really want to use it in one Activity. But then you have to check first if the SDK is already initialized with isInitialized(). So why do you want to check and initialize in every Activity with an ad when you can initialize the SDK on Application start up? – Sebastian Rieger Sep 07 '20 at 18:12
0

As qtmfld pointed out, your error is most likely happening in the RenderThread. My educated guess is that it has to do with your banner ad drawing on top of the map fragment.

There are known drawing issues when using hardcoded fragment elements in xml layouts, especially when using fragment transactions. Therefor, it is possible that SupportFragmentManager is somehow trying to draw over the banner ad when recreating the fragments state, which is causing the crash.

Apart from that, it is against Google's ad policies, to use banner ads above components, that the user interacts with.

To confirm this you can try changing your layout constraints so, that the banner ad doesn't overlay the maps fragment:

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@id/banner_container"
    tools:context=".MapsActivity" />
nulldroid
  • 1,150
  • 8
  • 15
  • Yes, it is against the Google Ad Policies, but that shouldn't cause any errors. Maybe a warning. But it's definitely a good hint to watch that policies out. – Sebastian Rieger Sep 07 '20 at 15:27
-1

Please check if you are using HAXM based emulator and check if it also happens in real devices.

You can also try Google Maps Android SDK v.3.1.0 BETA and see if the bug still exists.

wonsuc
  • 3,498
  • 1
  • 27
  • 30