0

If we use our native library using System.loadLibrary() then SupportMapFragment just kills activity after few seconds when it's launched. And it does that without any stacktrace. This is the best log I could collect:

06-10 02:10:01.063 22787-23766/com.myapp.staging E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.googlecertificates.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.myapp.staging-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.staging-1/lib/arm, /data/app/com.myapp.staging-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
06-10 02:10:01.063 22787-23766/com.myapp.staging W/ResourcesManager: getTopLevelResources: /data/app/com.google.android.gms-1/base.apk / 1.0 running in com.myapp.staging rsrc of package com.google.android.gms
06-10 02:10:01.063 22787-23766/com.myapp.staging I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:1
06-10 02:10:01.063 22787-23766/com.myapp.staging I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 1
06-10 02:10:01.153 23793-23793/? I/dex2oat: /system/bin/dex2oat --debuggable --compiler-filter=speed --dex-file=/data/user/0/com.google.android.gms/app_chimera/m/00000000/DynamiteModulesA_GmsCore_prodmnc_alldpi_release.apk --oat-file=/data/dalvik-cache/arm/data@user@0@com.google.android.gms@app_chimera@m@00000000@DynamiteModulesA_GmsCore_prodmnc_alldpi_release.apk@classes.dex
06-10 02:10:01.153 23793-23793/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@user@0@com.google.android.gms@app_chimera@m@00000000@DynamiteModulesA_GmsCore_prodmnc_alldpi_release.apk@classes.dex: Permission denied
06-10 02:10:01.153 23793-23793/? I/dex2oat: dex2oat took 721.250us (threads: 4) 
06-10 02:10:01.153 5853-5853/? E/audit: type=1701 msg=audit(1465506601.153:5185): auid=4294967295 uid=10329 gid=10329 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=23766 comm="androidmapsapi-" reason="memory violation" sig=11
06-10 02:10:01.153 3542-4463/? D/libgps: OnGpsExtensionMessage: message_id(1), data(0x7f95455e44), size(2432)
06-10 02:10:01.153 3542-4463/? D/libgps: GpsiHook: API: gpsSvStatusCb(GpsiHookStateGps: e,c,g)
06-10 02:10:01.153 3542-4463/? D/libgps: proxy__gps_sv_status_cb : called
06-10 02:10:01.173 3542-3607/? I/PassiveLocTracker: GPS Satllite Status
06-10 02:10:01.243 3542-4368/? I/WindowState: WIN DEATH: Window{ae4e596 u0 d0 com.myapp.staging/com.myapp.ui.activity.FrameActivity}
06-10 02:10:01.243 3067-4605/? D/libEGL: eglTerminate EGLDisplay = 0x7f6bae1f88
06-10 02:10:01.243 3067-4605/? D/libEGL: eglTerminate EGLDisplay = 0x7f6bae1f88
06-10 02:10:01.243 3542-4286/? D/GraphicsStats: Buffer count: 21
06-10 02:10:01.253 3542-4368/? D/InputDispatcher: Focus left window: 22787
06-10 02:10:01.253 3542-4639/? I/AppOps: sendInfoToFLP, code=41 , uid=10329 , packageName=com.myapp.staging , type=finishOp
06-10 02:10:01.253 3542-4120/? I/ActivityManager: Process com.myapp.staging (pid 22787)(adj 0) has died(114,1020)
06-10 02:10:01.253 3542-3564/? I/WindowState: WIN DEATH: Window{6ba02d0 u0 d0 com.myapp.staging/com.myapp.ui.activity.VisitActivity}
06-10 02:10:01.253 3542-4227/? I/AppOps: sendInfoToFLP, code=42 , uid=10329 , packageName=com.myapp.staging , type=finishOp
06-10 02:10:01.263 3542-4120/? D/ActivityManager: isAutoRunBlockedApp:: com.myapp.staging, Auto Run ON
06-10 02:10:01.263 3542-4120/? W/ActivityManager: Force removing ActivityRecord{6796427 u0 com.myapp.staging/com.myapp.ui.activity.FrameActivity t5324}: app died, no saved state

I have spent few days trying to understand what was causing it and it seems if we remove System.loadLibrary() call i.e. not use our native lib then SupportMapFragment works fine. Is there any way I can resolve it without removing our native lib?

EDIT: I created a sample app to reproduce this issue and after the above mentioned log I also got something which seems useful:

06-14 13:17:28.415 5756-5756/? E/audit: type=1701 msg=audit(1465892248.405:4500): auid=4294967295 uid=10332 gid=10332 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=6431 comm="androidmapsapi-" reason="memory violation" sig=11

EDIT2:

MapsActivity.java

public class MapsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Go.init(this);
    setContentView(R.layout.activity_maps);
}

public void showMap(View view) {
    getSupportFragmentManager().beginTransaction().replace(R.id.container, new MapFragment()).commit();
}
}

MapFragment.java

public class MapFragment extends android.support.v4.app.Fragment implements OnMapReadyCallback {

private GoogleMap mMap;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.map_frag, null, false);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
            .findFragmentById(R.id.maps);
    mapFragment.getMapAsync(this);

}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

Go.java

public final class Go {
// init loads libgojni.so and starts the runtime.
public static void init(final Context ctx) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        Log.wtf("Go", "Go.init must be called from main thread (thread="+Thread.currentThread().getName()+")");
    }
    if (running) {
        return;
    }
    running = true;

    // TODO(crawshaw): context.registerComponentCallbacks for runtime.GC

    System.loadLibrary("gojni");
    Go.run(ctx);
    new Thread("GoReceive") {
        public void run() { Seq.receive(); }
    }.start();
}

private static boolean running = false;

private static native void run(Context ctx);
}

This is the folder structure:

enter image description here

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
  • Does updating the Libs help? – PsyGik Jun 14 '16 at 07:57
  • `E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@user@0@com.google.android.gms@app_chimera@m@00000000@DynamiteModulesA_GmsCore_prodmnc_alldpi_release.apk@classes.dex: Permission denied` – Shark Jun 14 '16 at 07:58
  • 1
    @Shark yeah I saw that, but what is it? This log is not coming from my app. What can I do to solve it? – M-Wajeeh Jun 14 '16 at 08:04
  • Could you post the code where you are calling `System.loadLibrary` and using `SupportMapFragment`? Could you share the folder structure where you are holding your native library? – antonio Jun 14 '16 at 08:14
  • @antonio Just updated my question. – M-Wajeeh Jun 14 '16 at 08:27

1 Answers1

0

As far as I know, there are issues logged in gmaps-api-issues regarding memory leaks and the latest is issue 8596. And tracing back to other related issues, this has been fixed in recent version of the Google Maps Android API as mentioned in issue 4766, however, same issue was still encountered on other versions.

In addition to that, MapFragment also mentioned about memory leak caused when holding on to objects beyond the view's life as the view cannot be released.

And, this SO post - Google Maps Android API v2 SupportMapFragment memory leak might also help.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
  • Yeah I am already using the workaround of disabling location in `onDestroy()` by calling `setMyLocationEnabled(false)`. This also has nothing to do with the issue that I am facing because the memory leak only happen when finishing activity. – M-Wajeeh Jun 14 '16 at 17:53