0
由MonoDroid Professional生成的apk文件的文件大小非常大(18MB),我试图通过调用SDK程序集上的链接来减少它(选择'SDK Assemblies Only'when建造)。不幸的是,这失败了。Monodroid Linker对于简单的AsyncTask失败
下面是测试代码,演示了这个问题:
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;
}
,这里是在设备上运行时,它遇到的输出:
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):
我能够将文件大小减少到11MB,如果我跳过使用AndroidLinkSkip作为PropertyGroup链接MonoAndroid.dll。谢谢你的帮助。
感谢马修!你真的很棒。我们按照建议更改了代码,并设法将文件大小降至4.4MB。它现在非常出色! – 2012-03-13 23:40:06
@IronHarry谢谢!如果它有效,你可以接受我的答案 - 这将帮助其他人找到答案(我想要更多的代表);-) – Matthew 2012-03-14 06:47:01