当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Monodroid Linker Fails for Simple AsyncTask

问题描述:

The file size of the apk file generated by MonoDroid Professional is very large (18MB), and I'm trying to reduce it by invoking linking on the SDK assemblies (select 'SDK Assemblies Only' when building). Unfortunately, this fails.

Here's the test code that demonstrates the issue:

TestAsyncTask : AsyncTask<MyInt, int, int>

{

Activity1 _myActivity;

public TestAsyncTask(Activity1 activity)

: base()

{

_myActivity = activity;

}

protected override void OnPreExecute()

{

}

protected override int RunInBackground(params MyInt[] @params)

{

int taget = @params[0].IntValue;

Android.Util.Log.Debug("RunInBackground", taget.ToString());

System.Threading.Thread.CurrentThread.Join(1000);

return taget;

}

protected override void OnPostExecute(int results)

{

_myActivity.textView1.Text = results + " Complete!";

}

}

public class MyInt : Java.Lang.Object

{

public int IntValue;

}

and here's the output encountered when running it on device:

UNHANDLED EXCEPTION: System.ArgumentException: Couldn't bind to method 'GetDoInBackground_arrayLjava_lang_Object_Handler'.

at System.Delegate.GetCandidateMethod (System.Type,System.Type,string,System.Reflection.BindingFlags,bool,bool) <IL 0x0010c, 0x00728>

at System.Delegate.CreateDelegate (System.Type,System.Type,string,bool,bool) <IL 0x00018, 0x000f7>

at System.Delegate.CreateDelegate (System.Type,System.Type,string) <IL 0x00005, 0x00063>

at Android.Runtime.JNIEnv.RegisterJniNatives (intptr,int,intptr,intptr,int) <IL 0x00175, 0x00a03>

at (wrapper delegate-invoke) <Module>.invoke_intptr__this___intptr_intptr_string_string (intptr,intptr,string,string) <IL 0x0005d, 0x00117>

at Android.Runtime.JNIEnv.GetMethodID (intptr,string,string) <IL 0x00012, 0x000a7>

at Android.Runtime.JNIEnv.CreateInstance (intptr,string,Android.Runtime.JValue[]) <IL 0x00007, 0x00063>

at Android.Runtime.JNIEnv.CreateInstance (System.Type,string,Android.Runtime.JValue[]) <IL 0x0000a, 0x00093>

at Android.OS.AsyncTask`3<MonoAndroidApplication1.MyInt, int, int>..ctor () <IL 0x00049, 0x0015b>

at MonoAndroidApplication1.TestAsyncTask..ctor (MonoAndroidApplication1.Activity1) <IL 0x00001, 0x0005b>

at MonoAndroidApplication1.Activity1.OnCreate (Android.OS.Bundle) <IL 0x00035, 0x00213>

at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00012, 0x000e7>

at (wrapper dynamic-method) object.8bb95c67-1299-4094-bc2d-2b10b61aa06b (intptr,intptr,intptr) <IL 0x00012, 0x00033>

03-09 14:17:04.623 E/mono (20045):

I'm able to reduce the file size to 11MB if I skip linking for the MonoAndroid.dll using AndroidLinkSkip as a PropertyGroup. Thanks for your help.

网友答案:

Have a look at this:

Using Background Threads in Mono For Android Applications

I don't use any of Android's native multi-threading feature, but use the .NET versions. Often, all you need to do is :

ThreadPool.QueueUserWorkItem(state => { ... });
分享给朋友:
您可能感兴趣的文章:
随机阅读: