为什么xamarin无法连接调试器?

问题描述 投票:0回答:1

我决定编写自己的应用程序类来设置和获取当前的前台活动。但是,当我添加属性name=".PersonalOrgApp"时,Xamarin成功上传到电话更改中,但无法开始调试。删除此行后,应用程序正常运行。这是我的代码:AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          android:versionCode="1" 
          android:versionName="1.0" 
          package="com.companyname.finallyapp">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
  <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/AppTheme"
               android:name=".PersonalOrgApp">
  </application>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

和应用程序类:

public class PersonalOrgApp : Application
    {
        static private Activity mCurrentActivity = null;
        static private int mActivityId = -1;
        public override void OnCreate()
        {
            base.OnCreate();
        }
        public override void OnConfigurationChanged(Configuration newConfig)
        {
            base.OnConfigurationChanged(newConfig);
        }
        public override void OnLowMemory()
        {
            base.OnLowMemory();
        }
        public override void OnTerminate()
        {
            base.OnTerminate();
        }
        static public void SetCurrentActivity(Activity activity, int id)
        {
            mCurrentActivity = activity;
            mActivityId = id;
        }
        static public void SetCurrentActivity(Activity activity)
        {
            mCurrentActivity = activity;
        }
        static public Activity GetCurrentActivity()
        {
            return mCurrentActivity;
        }
        static public int GetActivityId()
        {
            return mActivityId;
        }
        static public void ClearReference(Activity activity)
        {
            if (activity.Equals(mCurrentActivity))
            {
                mActivityId = -1;
                mCurrentActivity = null;
            }
        }
    }

和日志:

[D:NotifyPhase]:          Upload completed
[D:GetLogCat]:            logcat -v time
[D:RunShellCommand]:      3300633ca56313c5 logcat -v time
[D:RunShellCommand]:      3300633ca56313c5 date +%s
[D:RunShellCommand]:      3300633ca56313c5 setprop "debug.mono.extra" "debug=127.0.0.1:29246:29247,timeout=1587899376,loglevel=0,server=y"
[D:RunShellCommand]:      3300633ca56313c5 getprop
[D:RunShellCommand]:      3300633ca56313c5 "echo" "-n" "${EMULATED_STORAGE_SOURCE}"
[D:RunShellCommand]:      3300633ca56313c5 "echo" "-n" "${EMULATED_STORAGE_TARGET}"
[D:RunShellCommand]:      3300633ca56313c5 am broadcast -a "mono.android.intent.action.EXTERNAL_STORAGE_DIRECTORY" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.ExternalStorageDirectory"
[D:RunShellCommand]:      3300633ca56313c5 am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.finallyapp/crc64a85b0d386beebbeb.MainActivity"
[D:RunShellCommand]:      3300633ca56313c5 ps
[D:RunShellCommand]:      3300633ca56313c5 am force-stop com.companyname.finallyapp
[D:RunShellCommand]:      3300633ca56313c5 setprop "debug.mono.connect" ""
visual-studio xamarin xamarin.android
1个回答
0
投票

您是否已将[Application]添加到PersonalOrgApp

而且您可能还需要添加public PersonalOrgApp(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip){}像:

[Application]
public class PersonalOrgApp : Application
{
    static private Activity mCurrentActivity = null;
    static private int mActivityId = -1;


    public PersonalOrgApp(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
    {
    }

    public override void OnCreate()
    {
        base.OnCreate();
    }
    public override void OnConfigurationChanged(Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
    }
    public override void OnLowMemory()
    {
        base.OnLowMemory();
    }
    public override void OnTerminate()
    {
        base.OnTerminate();
    }
    static public void SetCurrentActivity(Activity activity, int id)
    {
        mCurrentActivity = activity;
        mActivityId = id;
    }
    static public void SetCurrentActivity(Activity activity)
    {
        mCurrentActivity = activity;
    }
    static public Activity GetCurrentActivity()
    {
        return mCurrentActivity;
    }
    static public int GetActivityId()
    {
        return mActivityId;
    }
    static public void ClearReference(Activity activity)
    {
        if (activity.Equals(mCurrentActivity))
        {
            mActivityId = -1;
            mCurrentActivity = null;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.