Xamarin为Android 4创建应用程序(VS2017 15.5.5) [英] Xamarin create application for android 4 (VS2017 15.5.5)

查看:85
本文介绍了Xamarin为Android 4创建应用程序(VS2017 15.5.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用xamarin创建一个Android应用程序(VS 2017 15.5.5).默认设置(xamarin跨平台-空白应用程序/.net标准,针对android 7)生成可以通过实时播放器部署的项目,但是构建过程会产生错误

Error The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'XamTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'XamTest.dll'
....
....

我的目标是为android 4(4.0.3/4.1)和更高版本创建android应用程序,但是更改项目属性中的设置(目标框架+最低版本+目标android版本均设置为4.1)会导致15这些错误:

Error: NU1202 Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 supports: monoandroid70 (MonoAndroid,Version=v7.0)               
Error: No resource found that matches the given name: attr 'colorAccent'.   XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\Resources\values\styles.xml

因此,我删除了NuGet程序包管理器中的所有支持库,一些未定义的样式以及两个预生成的xaml文件(工具栏,任务栏).现在我有38个此类错误

\Dev\XamTest\XamTest\XamTest.Android\obj\Debug\resourcecache\96A6E7245B001AFA9465D8F3C01B0DCD\res\layout\notification_template_big_media.xml:42: error: No resource identifier found for attribute 'layoutDirection' in package 'android'   XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\C        

一个错误

Error NU1202 Package Xamarin.Android.Support.Design 23.3.0 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.Design 23.3.0 supports: monoandroid43 (MonoAndroid,Version=v4.3)                

没有链接支持库(仅xamarin.forms),所以我不明白Suppurt.Design的来源...

我花了两天时间进行研究,阅读文档,教程等,但是我没有找到任何合适的答案.那么,有什么简单的方法可以设置针对Android 4.1的Android项目?

谢谢.

解决方案

最新版本的Forms必须针对Android 8.0(至少)进行编译.为了针对API级别15 编译,您需要使用非常旧的Forms版本.

相反,请根据最新的API进行编译并设置您的最小值.并将API级别定位为4.0.3

General设置下,设置目标框架:

  • 目标框架:Use Latest installed platform (8.1)

在Android应用程序下:

  • 最低Android版本:Override - Android 4.0.3 (API level 15)

  • 目标Android版本:Override - Android 4.0.3 (API level 15)

这将导致清单包括:

<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />

注意:您需要针对Android 4.0.3设备/仿真器进行测试,以确保您未使用更高版本的Android SDK中的API.

im trying to create an android application with xamarin (VS 2017 15.5.5). The default settings (xamarin cross-platform - blank app / .net standard, targeting android 7) generates project that can be deployed via live player, but the build process generates error

Error The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'XamTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'XamTest.dll'
....
....

My goal is to create android application for android 4 (4.0.3 / 4.1) and higher, but changing the settings (target framework + min. version + target android ver. all set to 4.1) in project properties results in 15 errors of these kind:

Error: NU1202 Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 supports: monoandroid70 (MonoAndroid,Version=v7.0)               
Error: No resource found that matches the given name: attr 'colorAccent'.   XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\Resources\values\styles.xml

So i deleted all support libraries in NuGet package manager, some undefined styles and two pre-generated xaml files (Toolbar, Taskbar). Now i have 38 errors of this type

\Dev\XamTest\XamTest\XamTest.Android\obj\Debug\resourcecache\96A6E7245B001AFA9465D8F3C01B0DCD\res\layout\notification_template_big_media.xml:42: error: No resource identifier found for attribute 'layoutDirection' in package 'android'   XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\C        

and one error

Error NU1202 Package Xamarin.Android.Support.Design 23.3.0 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.Design 23.3.0 supports: monoandroid43 (MonoAndroid,Version=v4.3)                

No support library is linked (only xamarin.forms) so i dont understand where Suppurt.Design comes from...

I have spent two days with sdudying, reading doc, tutorials etc. but i havent found any suitable answer. So, is there any simple way how to set up an Android project targeting Android 4.1?

Thank you.

解决方案

The latest version of Forms needs to compile against Android 8.0 (at least). In order to compile against API level 15, you would need to use a very old version of Forms.

Instead, compile against the latest API and set your min. and target APIs levels to 4.0.3

Under General setting, set the target framework:

  • Target framework: Use Latest installed platform (8.1)

Under Android Application:

  • Min Android version: Override - Android 4.0.3 (API level 15)

  • Target Android version: Override - Android 4.0.3 (API level 15)

This results in a manifest that includes:

<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />

Note: You will need to test against an Android 4.0.3 device/emualtor to ensure that you are not using APIs from later versions of the Android SDK.

这篇关于Xamarin为Android 4创建应用程序(VS2017 15.5.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆