peoplewareDo / nativescript-svg

Nativescript plugin - support for .SVG file format
Other
70 stars 55 forks source link

SVG Image frm URL throws with android.os.NetworkOnMainThreadException #2

Open NickIliev opened 8 years ago

NickIliev commented 8 years ago

When I try to load online SVG file it throws an error. Code used:

<Page xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:svg="nativescript-svg" loaded="pageLoaded">
  <StackLayout>
    <svg:SVGImage src="https://media4.giphy.com/media/3uyIgVxP1qAjS/200.svg" height="200" />
  </StackLayout> 
</Page>  

Error throw:

java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.footballApp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onCreate failed

Error: Building UI from XML. @file:///app/main-page.xml:42:5
    android.os.NetworkOnMainThreadException
      android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
    java.net.InetAddress.lookupHostByName(InetAddress.java:431)
    java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
    java.net.InetAddress.getAllByName(InetAddress.java:215)
    com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
    com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
    com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
    com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
    com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
    com.android
NickIliev commented 8 years ago

same applies when using

var url = 'http://somepath/file.svg';
loaded = svgFile.loadFromUrl(url);
victorsosa commented 8 years ago

Thanks for report this issue; I submitted a patch for it; it seems like the http call was not async. Please try again with v1.1.1 and let me know if it works.

Please don't forget to add this to AndroidManifest.xml file: <uses-permission android:name="android.permission.INTERNET"/>

NickIliev commented 8 years ago

I have just tested 1.1.1 and unfortunately the same problem persists

victorsosa commented 8 years ago

I can't figure out this issue right not; PR are welcome