我创建了这个小应用程序。我构建了应用程序,当我点击图标时可以看到模拟器上的图标,页面打开时没有显示任何内容然后再次关闭而不显示任何错误。我取消了构建,然后在输出窗口中显示以下消息:
C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.0\zipalign.exe 4 "C:\VisualStudioMobileApplication\App3\App3\App3.Android\bin\Debug\com.companyname.app-Signed-Unaligned.apk" "bin\Debug\\com.companyname.app-Signed.apk"
1>Done building project "App3.Android.csproj" -- FAILED.
1>Build FAILED.
1>
1>Deploy failed on VisualStudio_android-23_arm_phone
1>Process was cancelled
Build has been canceled.
它不会给出任何错误。我还把断点放在" OnCreate" MainActivity.cs文件中的方法。即使单击App3图标,代码也不会在该断点上中断.Below是我的MainActivity.cs代码
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace App3.Droid
{
[Activity(Label = "App3", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Xamarin.FormsMaps.Init(this, bundle);
LoadApplication(new App());
}
}
}
MainPage.xaml上的代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App3"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="App3.MainPage">
<StackLayout VerticalOptions="StartAndExpand" Padding="30">
<maps:Map WidthRequest="960" HeightRequest="700"
x:Name="MyMap"
IsShowingUser="True"
MapType="Street"
/>
</StackLayout>
</ContentPage>
MainPage.xaml.cs中的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace App3
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyMap.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Position(37, -122), Distance.FromMiles(1)));
}
}
}
我使用的是Visual Studio 2017企业版15.6。整个项目的构建总是成功的。
以下是我的androidManifest.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.app" android:installLocation="auto">
<uses-sdk android:targetSdkVersion="27" />
<application android:label="app3.android">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyD1K1njDAN0"/>
</application>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
点击App3时,我真的需要帮助来显示地图。任何帮助将受到高度赞赏。
答案 0 :(得分:2)
在Windows上,如果您将Hyper-V用于模拟器,则可以尝试以下操作:
希望它有所帮助。干杯!