0

我正在创建一个应用程序“插件”dll,它在运行时为我的 Mono for Android 应用程序加载并启动一个新的活动。(该应用程序将临时安装 - 因此没有关于下载可执行代码的评论)

我来自 iOS 上的 Obj-C - 您可以在其中将 .nibs 和 ViewControllers 包含在库中。

我可以让主要的 Android 应用程序和加载的 dll 都引用另一个常见的 dll,并且加载对象就好了。

以下作品:

var test = plugin.CreateInstance("Test.Satellite.testClass");
MethodInfo getString = test.GetType().GetMethod("getString");
MethodInfo tryPatient = test.GetType().GetMethod("tryPatient");

在哪里

public class testClass
{
    public string getString ()
    {
        return "This was read from the object";
    }

    public string tryPatient ()
    {
        Patient p = new Patient();
        p.Name = "This was created from the Core/Common DLL";

        return p.Name;
    }
}

但是,当我尝试加载 Activity (通过CreateInstanceIntent/ StartActivity)时,会出现以下异常:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: test.satellite.RootActivity
  at Android.Runtime.JNIEnv.FindClass (System.String classname) [0x00087] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.7-branch/0e9eea34/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:275
  at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00009] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.7-branch/0e9eea34/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:233
  --- End of managed exception stack trace ---
  java.lang.NoClassDefFoundError: test.satellite.RootActivity
    at test.MainActivity.n_onCreate(Native Method)
    at test.MainActivity.onCreate(MainActivity.java:29)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.ClassNotFoundException: test.satellite.RootActivity in loader dalvik.system.PathClassLoader@44e8c678
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
    ... 15 more

  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x000e0, 0x00670>
  at System.Reflection.MethodBase.Invoke (object,object[]) <IL 0x00006, 0x0008f>
  at Test.MainActivity.OnCreate (Android.OS.Bundle) [0x001e9] in /Users/stephen/Projects/test/test/MainActivity.cs:86
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.7-branch/0e9eea34/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1490
  at (wrapper dynamic-method) object.ca46b703-b14e-4853-b371-499ea96364fc (intptr,intptr,intptr) <IL 0x00012, 0x00033>

我可以从中读出的是,Dalvik 找不到课程test.satellite.RootActivity- 但它找到test.satellite.testClass了就好了......?

任何帮助,将不胜感激。

4

1 回答 1

0

看起来你对包的大小写不一致。这可能是问题吗?

"Test.Satellite.testClass" -- works
"test.satellite.RootActivity" -- doesn't work
于 2012-11-29T00:37:32.330 回答