The DownloadHandlerScript is not invoked on android when I upgrade my code to Unity2017.
My code is compile in DLL and used in the project. In the editor it work fine, but on android device there is no any callback. The ReceiveData, CompleteContent and ReceiveContentLength is not invoked, but the UnityWebRequest is still finished.
I am using UnityWebRequest.Get to create a new UnityWebRequest, new a custom DownloadHandlerScript and assign it to the downloadHandler.
Can you show the code for it?
Also, since you compile it to a dll, does it work when it’s in a script?
I have try using the UnityWebRequest constructor instand using UnityWebRequest.Get but the result is the same.
My code is like this:
this.downloadBuffer = downloadBuffer;
this.handler = new DownloadHandlerBundle(
this.writer, downloadBuffer);
this.www = new UnityWebRequest(
this.url, UnityWebRequest.kHttpVerbGET, this.handler, null);
this.www.Send();
I customize the DownloadHandlerScript, and use a buffer pool as its internal buffer.
internal class DownloadHandlerBundle : DownloadHandlerScript
{
internal DownloadHandlerBundle(
AssetBundleCacheWriter writer,
byte[] preallocatedBuffer)
: base(preallocatedBuffer)
{
}
}
When I compile my code into DLL, I am using the CSharpCodeProvider:
var providerOptions = new Dictionary<string, string>(StringComparer.Ordinal);
providerOptions.Add("CompilerVersion", "v4.0");
using (var provider = new CSharpCodeProvider(providerOptions))
{
var results = provider.CompileAssemblyFromFile(parameters, sourceFiles);
if (results.Errors.Count > 0)
{}
Yes it a bit more complicated, I am trying to simplify it, using the script directly and see what will happen.
I found my problem because I am obfuscated my DLL. If I am not obfuscate the DLL, it work no problem on android device.
But I am doing the same thing in Uinty 5.6.x and everything is OK, it there any change broken this way?
The obfuscated result is like this, it seem nothing to wrong.
I am using the Obfuscar to obfuscated my DLL. And if I am turn on the “UseUnicodeNames” for better obfuscate, the android package will occur error with DownloadHandlerScript.
Is it use reflection to do something and does not support the unicode symbol name?
It always work well on Unity 5.x~
Sounds worth of bug report.
I have no idea where to add the issue.
You can report bugs from Unity editor Help menu.
I am wrong, this problem has no relationship obfuscated.
I write this code and compile it into dll without any obfuscated:
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public sealed class GameTest : MonoBehaviour
{
private IEnumerator Start()
{
var handler = new MyDownloadHandler();
var www = new UnityWebRequest(
"http://www.bbc.com",
UnityWebRequest.kHttpVerbGET,
handler,
null);
Debug.Log("Start web request: " + www.url);
yield return www;
Debug.Log("Complete web request: " + www.responseCode);
}
}
public sealed class MyDownloadHandler : DownloadHandlerScript
{
/// <inheritdoc/>
protected override bool ReceiveData(byte[] data, int dataLength)
{
Debug.LogError("ReceiveData: " + dataLength);
return true;
}
/// <inheritdoc/>
protected override void CompleteContent()
{
Debug.LogError("CompleteContent.");
}
/// <inheritdoc/>
protected override void ReceiveContentLength(int contentLength)
{
Debug.LogError("ReceiveContentLength: " + contentLength);
}
}
The log inside the ‘MyDownloadHandler’ is never invoked. I test it on android simulator on windows.
This line is wrong!
Your should do:
yield return www.Send();
I have same problem,can you tell me how to fix it?
“The DownloadHandlerScript is not invoked on android when I upgrade my code to Unity2017.
My code is compile in DLL and used in the project. In the editor it work fine, but on android device there is no any callback. The ReceiveData, CompleteContent and ReceiveContentLength is not invoked, but the UnityWebRequest is still finished.”
I’ve got the same problem, finally I found it’s due to stripping level, my project use “medium” stripping level and got the problem.
after I preserve the UnityEngine.UnityWebRequestModule in link.xml, all works fine!
link.xml ust like this:
<?xml version="1.0" encoding="utf-8"?>I think it is a bug about the code strip. There is nothing about reflection, and code stripper should work with this.