2017-06-13 75 views
0

,同時添加作爲可移植項目的引用的Android項目它說引用無法添加,它會導致循環依賴項,我有一個視圖在android項目中,需要調用從便攜式項目,請在這方面幫助我。問題,同時添加Android項目作爲參考到便攜式項目

+0

添加一個android項目作爲對可移植項目的引用是不可能的。如果你需要從你的PCL調用一個視圖,而不是它應該如何工作。 – woelliJ

+0

你爲什麼這樣做? –

回答

0

無法在便攜式項目中添加Android項目。如果你想從Android項目得到任何邏輯請參考下面的步驟

在PCL創建這樣的接口

public interface PortableInterface 
    { 
     object GetLogicFromAndroidProject(); 
    } 

添加擴展這個接口在你的Android項目類似下面

using System; 
using Xamarin.Forms; 
[assembly: Dependency(typeof(PortableInterfaceRenderer))] 
namespace YourProjectName.iOS 
{ 

    public class PortableInterfaceRenderer : PortableInterface 
    { 
     public object GetLogicFromAndroidProject() 
     { 
      throw new NotImplementedException(); // here write your logic 
     } 
    } 
} 

現在你必須在PCL項目中調用此方法

var obj = DependencyService.Get<PortableInterface>().GetLogicFromAndroidProject(); 

希望這會h elp