關(guān)于 Xamarin 的那些事(三)-使用 Jar 庫

使用 Xamarin 的過程中,難免會(huì)有需要使用原生的第三方庫,畢竟 C# 的第三方庫還不完善,尤其是國內(nèi)服務(wù)的庫,比如說第三方登陸,分享,支付等等。

為了節(jié)省時(shí)間,這里提供一些已經(jīng)轉(zhuǎn)好的 Android SDK 供大家使用

你也可以自行建立一個(gè) Jar 的映射,使得 Xamarin 也能使用 Java 的庫,不過在自動(dòng)生成的代碼中,由于 C# 和 Java 的差異導(dǎo)致會(huì)出現(xiàn)很多錯(cuò)誤。

以下是一些映射時(shí)常見的錯(cuò)誤,解決代碼請(qǐng)放到 Metadata.xml 里面(查看 Xamarin 生成的代碼可以看到每個(gè)類和方法的 Path):


Error CS0507

'Class.Method(Parameter)': cannot change access modifiers when overriding 'protected' inherited member 'Class.Method(Parameter)'

解決辦法

<pre><attr path="Path" name="visibility">protected</attr></pre>


Error CS0535

'Class' does not implement interface member 'Interface(Parameter)' (CS0535)

解決辦法

<pre><attr path="Path" name="managedType">Java.Lang.Object</attr></pre>


Error CS0234

The type or namespace name 'Class' does not exist in the namespace 'Namespace' (are you missing an assembly reference?)

常見解決辦法

<pre><attr path="Path" name="visibility">public</attr>
<attr path="Path" name="name">NewClass</attr></pre>


Error CS0542

'Method': member names cannot be the same as their enclosing type

解決辦法

<pre><attr path="Path" name="managedName">NewClass</attr></pre>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容