我使用Xamarin(最新版)和Visual Studio 2015创建了 Cross-Plattform - 应用程序 - 项目(原生共享)。
我按照教程“Hello Android”完成了它,但在构建项目时我会收到以下错误消息:
严重级代码描述项目文件行抑制状态 错误CS0117 'Resource.Id'不包含的定义 'CallButton' HelloApp.Droid C:\ Users \ username \ documents \ visual studio 2015 \ Projects \ HelloApp \ HelloApp \ HelloApp \ HelloApp.Droid \ MainActivity.cs 26 Active
(与其他小部件相同)
我尝试了不同的API级别/重新安装的sdks和软件包,如this Question中所述,但它对我不起作用。我为不同的API级别安装了Android Build Tools并卸载了其他API,但这不会改变一件事。
我也试过了这个问题中陈述的solution并尝试多次清理和重建解决方案,我还删除了xamarin-zips文件夹中的拉链。每次都会编译Resource.designer.cs并且看起来很好......而且Build Action对所有文件都是正确的。
有人可以帮忙吗?
PS:在Mac上它运行得很好,但我想在Windows上用Visual Studio开发......
链接到教程: https://developer.xamarin.com/guides/android/getting_started/hello,android/hello,android_quickstart/
有关详细信息,请参阅我的源代码:
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="HelloApp.Droid"></application>
</manifest>
PhonewordTranslator.cs
using System.Text;
using System;
namespace Core
{
public static class PhonewordTranslator
{
public static string ToNumber(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
return "";
else
raw = raw.ToUpperInvariant();
var newNumber = new StringBuilder();
foreach (var c in raw)
{
if (" -0123456789".Contains(c))
newNumber.Append(c);
else
{
var result = TranslateToNumber(c);
if (result != null)
newNumber.Append(result);
}
// otherwise we've skipped a non-numeric char
}
return newNumber.ToString();
}
static bool Contains(this string keyString, char c)
{
return keyString.IndexOf(c) >= 0;
}
static int? TranslateToNumber(char c)
{
if ("ABC".Contains(c))
return 2;
else if ("DEF".Contains(c))
return 3;
else if ("GHI".Contains(c))
return 4;
else if ("JKL".Contains(c))
return 5;
else if ("MNO".Contains(c))
return 6;
else if ("PQRS".Contains(c))
return 7;
else if ("TUV".Contains(c))
return 8;
else if ("WXYZ".Contains(c))
return 9;
return null;
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Enter a Phoneword"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PhoneNumberText"
android:text="1-855-XAMARIN" />
<Button
android:text="Translate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TranslateButton" />
<Button
android:text="CallButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CallButton" />
</LinearLayout>
MainActivity.cs
using System;
using Android;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace Phoneword
{
[Activity(Label = "Phoneword", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
//** ERROR IN THE NEXT 4 LINES!!! **
SetContentView(Resource.Layout.Main);
EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
Button callButton = FindViewById<Button>(Resource.Id.CallButton);
callButton.Enabled = false;
// Add code to translate number
string translatedNumber = string.Empty;
translateButton.Click += (object sender, EventArgs e) =>
{
// Translate user's alphanumeric phone number to numeric
translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
if (String.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call " + translatedNumber;
callButton.Enabled = true;
}
};
callButton.Click += (object sender, EventArgs e) =>
{
// On "Call" button click, try to dial phone number.
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("Call " + translatedNumber + "?");
callDialog.SetNeutralButton("Call", delegate {
// Create intent to dial phone
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("Cancel", delegate { });
// Show the alert dialog to the user and wait for response.
callDialog.Show();
};
// Our code will go here
}
}
}
Resource.designer.cs
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Android.Runtime.ResourceDesignerAttribute("HelloApp.Droid.Resource", IsApplication=true)]
namespace HelloApp.Droid
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
public partial class Resource
{
static Resource()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
public static void UpdateIdValues()
{
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int Icon = 2130837504;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050003
public const int CallButton = 2131034115;
// aapt resource value: 0x7f050001
public const int PhoneNumberText = 2131034113;
// aapt resource value: 0x7f050002
public const int TranslateButton = 2131034114;
// aapt resource value: 0x7f050000
public const int textView1 = 2131034112;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int layout1 = 2130903040;
// aapt resource value: 0x7f030001
public const int Main = 2130903041;
static Layout()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Layout()
{
}
}
public partial class String
{
// aapt resource value: 0x7f040001
public const int app_name = 2130968577;
// aapt resource value: 0x7f040000
public const int hello = 2130968576;
static String()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private String()
{
}
}
}
}
#pragma warning restore 1591
答案 0 :(得分:1)
我也有这个错误 我做的只是保存文件,它修复了!希望能帮到你。
答案 1 :(得分:1)
1。删除“ {yourAPPlocation} \ Resources \ Resource.designer.cs”中的所有内容。
2。重建整个项目。
3。复制整个“ {yourAPPlocation} \ Resources \ Resource.designer.cs”新生儿并粘贴到 “ {yourAPPlocation} \ obj \ Debug \ 81 \ designtime \ Resource.designer.cs”。
然后它起作用了!
希望在您的项目上也能成功。