title: Android 11 - System.loadLibrary for native C++ library takes 60+ seconds, works perfectly fast on Android 10 and below
body: <p>In our game application for Android which is based on the game engine cocos2d-x, with most of the code being written in C++, we have a very strange and critical issue since Android 11:</p>
  <p>When the native library gets loaded in <code>onLoadNativeLibraries</code> it now suddenly takes 60+ seconds. Before Android 11, it all worked fine and it loaded in 0.2-3 seconds. Now when you start the game, you have a 60+ seconds gray screen.</p>
  <p>We already figured out that <code>JNI_OnLoad</code> gets called directly after the 60 second stall is over.</p>
  <p>Here's the code of the <code>onLoadNativeLibraries</code>
  function:</p>
  <pre><code>protected void onLoadNativeLibraries()
  {
      try
      {
          ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
          Bundle bundle = ai.metaData;
          String libName = bundle.getString(&quot;android.app.lib_name&quot;);
          System.loadLibrary(libName); // line of 60 seconds stall
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  <p>We already tried time profiling, but without any success. It just hows that it's spending a lot of time on that function. Also pausing via the debugging doesn't lead to any further clues. The native debugger doesn't show anything on the C++ side of the code.</p>
  <p>Does anybody have any idea why this is happening or what we could try to figure it out? Any help would be highly appreciated :)</p>