简体   繁体   English

离子Android模拟器问题

[英]Ionic Android Emulator issue

from my app i refer to external API to get data. 从我的应用程序中,我引用外部API来获取数据。 on browser and built version everything works fine, but on emulator request get rejected. 在浏览器和内置版本上,一切正常,但在模拟器请求上被拒绝。 on actual device app works just fine. 在实际的设备上运行就可以了。 for debugging i need to test on emulator but i get this error. 对于调试,我需要在模拟器上进行测试,但出现此错误。 i checked every article possible but couldn't find solution. 我检查了所有可能的文章,但找不到解决方案。 here is my configuration 这是我的配置

IONIC INFO 离子信息

Cordova CLI: 6.4.0
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
OS: Distributor ID: Ubuntu Description: Ubuntu 15.10 
Node Version: v6.3.1

CONFIG.XML 配置文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.freemusic372670" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>
        FreeMusic
    </name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com.com/">
        Your Name Here
    </author>
  <access origin="*"/>
  <allow-intent href="*"/>
  <allow-navigation href="http://*/*"/>
  <allow-navigation href="https://*/*"/>
  <allow-navigation href="data:*"/>
  <allow-navigation href="http://10.11.11.127:8100"/>
  <allow-navigation href="http://10.11.11.127:8101"/>
  <allow-navigation href="http://192.168.42.87:8100"/>
  <content src="index.html"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreenDelay" value="2000"/>
  <preference name="FadeSplashScreenDuration" value="2000"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
  <platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
</widget>

META HEADER in index.html index.html中的META HEADER

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

PLUGINS 插件

cordova-plugin-whitelist

ERROR 错误

{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://databrainz.com/api/search_api.cgi?qry=metallica&format=json&mh=50&where=mpl","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}

LOGCAT ERROR LOGCAT错误

11-30 11:51:50.971 3179-3179/com.ionicframework.freemusic372670 D/SystemWebChromeClient: http://10.11.11.127:8100/#/tab/dash: Line 0 : XMLHttpRequest cannot load http://databrainz.com/api/search_api.cgi?qry=metallica&format=json&mh=50&where=mpl. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.11.11.127:8100' is therefore not allowed access.

You must enable CORS by your webserver. 您必须通过Web服务器启用CORS Your Error mentioned this out: 您的错误提到了这一点:

…No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.11.11.127:8100' is therefore not allowed access.…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM