title: Phonegap/Cordova App breaks in Jelly Bean - Access-Control-Allow-Origin and setAllowUniversalAccessFromFileURLs
body: <p>I've been developing* with Cordova (aka Phonegap) for Android for well over a year now and am trying to make my apps available to run in Jelly Bean, but I am getting the following error:</p>
  
  <pre><code>XMLHttpRequest cannot load http://127.0.0.1:40582/[somerandomstring]. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
  </code></pre>
  
  <p>(and similar errors for any subsequent ajax requesting use of localhost or file://)
  Just to test, I grant access to everything in the config.xml in the section for Access-Control-Allow-Origin</p>
  
  <pre><code>&lt;access origin="*"/&gt;
  &lt;access origin="http://127.0.0.1*"/&gt;
  </code></pre>
  
  <p>In my <a href="http://mail-archives.apache.org/mod_mbox/incubator-callback-dev/201207.mbox/%3C1268020324.77523.1342724256053.JavaMail.jiratomcat@issues-vm%3E" rel="nofollow noreferrer">research</a> I have discovered the error is related to a setting change that Google made as of Android Jelly Bean. Here is what I found:
  From: <a href="https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=commitdiff;h=07439ff9" rel="nofollow noreferrer">https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=commitdiff;h=07439ff9</a></p>
  
  <p>-- This is from org.apache.cordova.CordovaWebView</p>
  
  <pre><code>// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
  // while we do this
  if (android.os.Build.VERSION.SDK_INT &gt; android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
      Level16Apis.enableUniversalAccess(settings);
  </code></pre>
  
  <p>-- This is also from org.apache.cordova.CordovaWebView</p>
  
  <pre><code>// Wrapping these functions in their own class prevents warnings in adb like:
  // VFY: unable to resolve virtual method 285: Landroid/webkit/WebSettings;.setAllowUniversalAccessFromFileURLs
  @TargetApi(16)
  private static class Level16Apis {
      static void enableUniversalAccess(WebSettings settings) {
           settings.setAllowUniversalAccessFromFileURLs(true);
       }
  }
  </code></pre>
  
  <p>It's nice that Cordova tried to work around the change, but unfortunately this does not work...</p>
  
  <p>In these SO threads <a href="https://stackoverflow.com/a/11511062/1013526">here</a> and <a href="https://stackoverflow.com/a/12029490/1013526">here</a> I found a common solution, to simply change a setting as follows:</p>
  
  <pre><code>if(android.os.Build.VERSION.SDK_INT &gt; android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
      super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);    
  }
  </code></pre>
  
  <p>Now I get the following warning:</p>
  
  <pre><code>Call requires API level 16 (current min is 8) 
  android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs
  </code></pre>
  
  <p>Here is what I have for the api in my AndroidManifest.xml</p>
  
  <pre><code>&lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt;
  </code></pre>
  
  <p>Why is it requiring me to change the minSdkVersion to 16 rather than follow my targetSdkVersion which is 16?</p>
  
  <p>Thoughts?</p>
  
  <p><strong>Notes</strong>: I'm currently using Cordova 2.0, Eclipse Indigo SR2 (all updates current), Android SDK (all updates current), on Windows 7 Home (all updates current), Java 7 Update 7.</p>