2016-10-25 1 views
0

저는 Visual Studio에서 Xamarin에 초보자입니다. Jar 파일 (SDK)을 추가해야하는 기존 xamarin android 프로젝트가 있으므로 바인딩 라이브러리를 만들었지 만 Metadata.xml을 사용하여 해결하려고하는 일부 오류가 발생했습니다. 그 중 하나는 다음과 같이이 인터페이스에서오류 CS0535 클래스가 인터페이스 멤버를 구현하지 않습니다

<class abstract="false" deprecated="not deprecated" extends="android.app.Service" extends-generic-aware="android.app.Service" final="false" name="DeviceService" static="false" visibility="public"> 
<implements name="com.company.deviceService.IDeviceService" name-generic-aware="com.company.deviceService.IDeviceService"> 
</implements> 
<constructor deprecated="not deprecated" final="false" name="DeviceService" static="false" type="com.company.deviceService.DeviceService" visibility="public"> 
</constructor> 
... 
<method abstract="false" deprecated="not deprecated" final="false" name="setSignResult" native="false" return="void" static="false" synchronized="false" visibility="public"> 
<parameter name="p0" type="int"> 
</parameter> 
</method> 

<method abstract="false" deprecated="not deprecated" final="false" name="getSignResult" native="false" return="int" static="false" synchronized="false" visibility="public"> 
</method> 
... 
</class> 

:

'DeviceService는'api.xml으로 검색 인터페이스 멤버 'IDeviceService.SetSignResult (INT)'

를 구현하지 않습니다 이걸 발견했습니다 그러한 방법 :

IntPtr id_setSignResult_I; 
     public unsafe void SetSignResult (int p0) 
     { 
      if (id_setSignResult_I == IntPtr.Zero) 
       id_setSignResult_I = JNIEnv.GetMethodID (class_ref, "setSignResult", "(I)V"); 
      JValue* __args = stackalloc JValue [1]; 
      __args [0] = new JValue (p0); 
      JNIEnv.CallVoidMethod (Handle, id_setSignResult_I, __args); 
     } 
내가 생성 된 클래스 DeviceService.cs로 검색 할 때

그러나 나는이 발견, 나도 몰라 발전기 잘못 메소드 구현 또는 반환 유형을 추론 바인딩 어떤 이유로

static Delegate cb_setSignResult_I; 
#pragma warning disable 0169 
     static Delegate GetSetSignResult_IHandler() 
     { 
      if (cb_setSignResult_I == null) 
       cb_setSignResult_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_SetSignResult_I); 
      return cb_setSignResult_I; 
     } 

     static void n_SetSignResult_I (IntPtr jnienv, IntPtr native__this, int p0) 
     { 
      global::com.company.deviceService.DeviceService __this = global::Java.Lang.Object.GetObject<global::com.company.deviceService.DeviceService> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); 
      __this.SignResult = p0; 
     } 
#pragma warning restore 0169 

     static IntPtr id_getSignResult; 
     static IntPtr id_setSignResult_I; 

     public virtual unsafe int SignResult { 
      // Metadata.xml XPath method reference: path="/api/package[@name='com.company.deviceService']/class[@name='DeviceService']/method[@name='getSignResult' and count(parameter)=0]" 
      [Register ("getSignResult", "()I", "GetGetSignResultHandler")] 
      get { 
       if (id_getSignResult == IntPtr.Zero) 
        id_getSignResult = JNIEnv.GetMethodID (class_ref, "getSignResult", "()I"); 
       try { 

        if (GetType() == ThresholdType) 
         return JNIEnv.CallIntMethod (Handle, id_getSignResult); 
        else 
         return JNIEnv.CallNonvirtualIntMethod (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "getSignResult", "()I")); 
       } finally { 
       } 
      } 
      // Metadata.xml XPath method reference: path="/api/package[@name='com.company.deviceService']/class[@name='DeviceService']/method[@name='setSignResult' and count(parameter)=1 and parameter[1][@type='int']]" 
      [Register ("setSignResult", "(I)V", "GetSetSignResult_IHandler")] 
      set { 
       if (id_setSignResult_I == IntPtr.Zero) 
        id_setSignResult_I = JNIEnv.GetMethodID (class_ref, "setSignResult", "(I)V"); 
       try { 
        JValue* __args = stackalloc JValue [1]; 
        __args [0] = new JValue (value); 

        if (GetType() == ThresholdType) 
         JNIEnv.CallVoidMethod (Handle, id_setSignResult_I, __args); 
        else 
         JNIEnv.CallNonvirtualVoidMethod (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "setSignResult", "(I)V"), __args); 
       } finally { 
       } 
      } 
     } 

을하고 api.xml로보고 그것을 올바른 방법으로 보인다 : void setSignResult (int p0). 나는 같은 오류와 함께 metadata.xml를 사용하여 동작을 수정하려고 :

나는 다른 인터페이스 메소드 구현을 찾았다
<attr path="/api/package[@name='Com.Company.deviceservice']/class[@name='DeviceService']/method[@name='SetSignResult' 
    and count(parameter)=1 
    and parameter[1][@type='int']]/parameter[1]" 
    name="managedReturn">Java.Lang.Void</attr> 

, 모양에 걸릴 앞서 언급 한 유사 그것과 비교, 나는 제대로 된 방법을 생성 발견 :

static IntPtr id_bcrSymbologyToText_I; 
     [Register ("bcrSymbologyToText", "(I)Ljava/lang/String;", "GetBcrSymbologyToText_IHandler")] 

     public virtual unsafe string BcrSymbologyToText (int p0) 
     { 
      if (id_bcrSymbologyToText_I == IntPtr.Zero) 
       id_bcrSymbologyToText_I = JNIEnv.GetMethodID (class_ref, "bcrSymbologyToText", "(I)Ljava/lang/String;"); 
      try { 
       JValue* __args = stackalloc JValue [1]; 
       __args [0] = new JValue (p0); 

       if (GetType() == ThresholdType) 
        return JNIEnv.GetString (JNIEnv.CallObjectMethod (Handle, id_bcrSymbologyToText_I, __args), JniHandleOwnership.TransferLocalRef); 
       else 
        return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "bcrSymbologyToText", "(I)Ljava/lang/String;"), __args), JniHandleOwnership.TransferLocalRef); 
      } finally { 
      } 
     } 

조만간 도움이 필요하십니까?

+0

감사 "IntPtr입니다 id_setSignResult_I을;" 함수 안에? 함수 외부에있을 때 대리자를 설정해야하는 것 같습니다. 또한 문제가있는 함수에서 누락 된 다른 함수 레지스터 선언을 볼 수 있습니다. –

+0

아니요, IntPtr id_setSignResult_I를 움직이지 않았습니다. 같은 오류. –

+0

[등록] 속성은 어떻습니까? 왜 SetSignResult 그것을 가지고 있지만 BcrSymbologyToText 가지고 있지? –

답변

0

찾을 답 :

자 마린 (바인딩 라이브러리에서 작동) 발전기, C#을 클래스가 reingenieering 수행 할 수있는 몇 가지 자바 코드에 자바 클래스에서 잘못된 방법으로 번역되는 바인딩 때문에 발전기가 만드는 것입니다 Java 메소드의 프로퍼티 결과로서 setSignResult 이러한 문제를 해결하는 방법은 일부 오류 유형에 대해 metadata.xml을 사용하는 것이고, 내 경우에는 동일한 자동 생성 클래스 이름을 사용하여 부분 클래스를 작성하여 누락 된 메소드를 구현하는 것입니다.

public partial class DeviceService 
    { 
     public void SetSignResult(int p) 
     { 
      SignResult = p; 
     } 
} 

완벽한 작품 : 발전기 자체 구현 DeviceService 부분 클래스를 만들었 바인딩 때문에, 나는 다음과 같은 구현 방법 누락 구현하는 또 다른 DeviceService 부분 클래스를 만들었습니다! 당신이 이동하려고 할 수있는 모든

관련 문제