Xamarin仅错误Android 6.0 Mono.AndroidTools.InstallFailedException和NSTALL_PARSE_FAILED_MANIFEST_MALFORMED

时间:2019-05-19 23:01:02

标签: java android visual-studio xamarin xamarin.android

我使用Visual Studio Professional 2017在Xamarin中创建了一个项目,该项目正常进行清理/构建/编译,并安装在Android 7.0、7.1、8.0、8.1和9.0(模拟器和设备)上。

compile and build ok

但是,请勿在Android 6.0和6.1(模拟器或设备)上安装/构建,我尝试在模拟器和设备上安装,显示错误:

install fail in android 6.0

1>C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\\bin\keytool.exe -list -alias androiddebugkey -storepass android -keypass android -keystore "C:\Users\Claudio\AppData\Local\Xamarin\Mono for Android\debug.keystore" 
1>C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\zipalign.exe 4 "C:\Workspace\htdocs\Projetos\aprepara-xamarin-raksha\Ishpia.Droid\obj\Debug\81\android\bin\com.bergmannsoft.aprepara.apk" "bin\Debug\\com.bergmannsoft.aprepara-Signed.apk" 
1>C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\lib\apksigner.jar" sign --ks "C:\Users\Claudio\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 22 --max-sdk-version 27  C:\Workspace\htdocs\Projetos\aprepara-xamarin-raksha\Ishpia.Droid\bin\Debug\com.bergmannsoft.aprepara-Signed.apk 
1>ADB0000:  Deployment failed
1>Mono.AndroidTools.InstallFailedException: Unexpected install output:  pkg: /data/local/tmp/com.bergmannsoft.aprepara-Signed.apk
1>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
1>
1>   em Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) na E:\A\_work\1824\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:linha 345
1>   em Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task`1 t) na E:\A\_work\1824\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:linha 753
1>   em System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
1>   em System.Threading.Tasks.Task.Execute()
1>ADB0010: Unexpected install output:   pkg: /data/local/tmp/com.bergmannsoft.aprepara-Signed.apk
1>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
1>
1>   em Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) na E:\A\_work\1824\s\External\androidtools\Mono.AndroidTools\Internal\AdbOutputParsing.cs:linha 345
1>   em Mono.AndroidTools.AndroidDevice.<>c__DisplayClass95_0.<InstallPackage>b__0(Task`1 t) na E:\A\_work\1824\s\External\androidtools\Mono.AndroidTools\AndroidDevice.cs:linha 753
1>   em System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
1>   em System.Threading.Tasks.Task.Execute()
1>Projeto de compilação pronto "Ishpia.Droid.csproj" -- FALHA.
1>FALHA da compilação.
1>Deployment failed to nexus_5x_api_23.
========== Compilar: 0 com êxito, 0 com falha, 2 atualizados, 0 ignorados ==========
========== Implantação: 0 com êxito, 1 com falha, 0 ignorados ==========

已经多次清理,删除文件夹“ bin”和“ obj”,清除了缓存包,nuget并始终显示错误。

谁能帮助我理解为什么错误仅在Android 6.0 / 6.1中发生?

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="150" android:versionName="3.2" package="com.bergmannsoft.aprepara" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="27" />
  <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <!-- We need to be able to download map tiles and access Google Play Services-->
  <uses-permission android:name="android.permission.INTERNET" android:required="true" />
  <uses-permission android:name="android.permission.CAMERA" android:required="true" />
  <!-- Allow the application to access Google web-based services. -->
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <!-- Google Maps for Android v2 will cache map tiles on external storage -->
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:required="true" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />
  <!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true" />
  <!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="true" />
  <!-- Outras permissoes-->
  <uses-permission android:name="android.permission.CALL_PHONE" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" android:required="true" />
  <!-- Permission to receive remote notifications from Google Play Services -->
  <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
  <uses-permission android:name="com.bergmannsoft.aprepara.permission.MAPS_RECEIVE" android:required="true" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" android:required="true" />
  <uses-permission android:name="android.permission.READ_USER_DICTIONARY" android:required="true" />
  <!-- GCM-->
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
  <uses-permission android:name="com.bergmannsoft.aprepara.permission.C2D_MESSAGE" />
  <permission android:name="com.bergmannsoft.aprepara.permission.C2D_MESSAGE" android:protectionLevel="signature" />
  <!-- BOOT -->
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <!-- MAP-->
  <permission android:name="com.bergmannsoft.aprepara.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <!-- Declaring Service in Manifest -->
  <service android:name="Ishpia.Droid.Activities.Services.Order.PostService" android:exported="false" />
  <service android:name="Ishpia.Droid.Activities.Services.Order.OrderService" android:exported="false" />
  <service android:name="Ishpia.Droid.Activities.Services.Periodic.PeriodicService" android:exported="false" />
  <!-- APLICATION -->
    <application android:allowBackup="true" android:label="@string/app_title" android:icon="@mipmap/icon" android:roundIcon="@mipmap/icon_round" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBarNotExtended">
    <!-- Put your Google Maps V2 API Key here. -->
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXXXXXXXXXXXXXXXXXXX" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <!-- FCM/GCM -->
    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
    <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/background" />
    <!-- [END fcm_default_icon] -->
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="${applicationId}" />
      </intent-filter>
    </receiver>
    <!-- BOOT DEVICE -->
    <receiver android:name="Ishpia.Droid.Activities.Services.Boot.BootReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </receiver>
    <!-- FILE PROVIDER -->
    <provider android:name="android.support.v4.content.FileProvider" android:grantUriPermissions="true" android:exported="false" android:authorities="${applicationId}.fileprovider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths" />
    </provider>
    </application>
</manifest>

3 个答案:

答案 0 :(得分:1)

该错误表明您的清单格式错误:

  

“ INSTALL_PARSE_FAILED_MANIFEST_MALFORMED”

如果我尝试将您的清单加载到Chrome中,它也会在那里出错。

此评论没有结束标签:

<!-- Set color used with incoming notification messages. This is used when no

我相信这可能是您的问题。

如果是这样,有趣的是其他版本的Android忽略了XML格式错误。

答案 1 :(得分:0)

老实说,这个问题令我非常困惑。但是,Robert Bruce(@ 6157192)是正确的,问题出在Manifest.xml中,但不是在Manifest.Xml配置中,而是在构建后生成的Manifest.Xml中。

我将描述为我找到最佳“解决方案”的步骤:

1。 。我多次运行Android Lint(@SushiHangover / @ 4984832),进行必要的调整,检查并清理了Manifest.xml主要文件。

C:\Workspace\Android\sdk\tools\bin>lint.bat  C:\Workspace\htdocs\Projetos\aprepara-xamarin-raksha\Ishpia.Droid\

2。 。使用Visual Studio 2017和Androi Emulator Nexus 5x(API 23)进行了清理,重新编译和部署。

很明显,该错误发生了,但是,如果您查看输出终端,则会生成apk进行安装。

C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\lib\apksigner.jar" sign --ks "C:\Users\Claudio\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 22 --max-sdk-version 27  C:\Workspace\htdocs\Projetos\aprepara-xamarin-raksha\Ishpia.Droid\bin\Debug\ **com.bergmannsoft.aprepara-Signed.apk**

com.bergmannsoft.aprepara-Signed.apk

3。 。在win中使用apkanalyzer,在编译后导出了生成的manifest.xml。

apkanalyzer.cmd manifest print C:\Workspace\htdocs\Projetos\aprepara-xamarin-raksha\Ishpia.Droid\bin\Debug\com.bergmannsoft.aprepara-Signed.apk > android.xml

现在游戏变得很有趣,因为经过几天的回顾和重新制作了Manifest.xml,我发现该错误出在编译后生成的Manifest.xml中,这是因为取决于其class Xamarin的实现(不确定是否只是Xamarin)将操纵XML并添加其他信息。

错误实际上出在Manifest.xml中,而不是编辑后在编译后生成的。

Boot Receiver权限和类已生成两次。

4 。现在我终于找到了错误所在,我们回到了测试..测试..测试..许多测试。

测试A(失败):

删除操作Manifest.xml并生成错误的属性的类,并将所有程序包名称都用小写形式显示在“ Manifest”中,则该应用程序已正确安装在Android 6.0和其他版本(7.8和9)上

<!-- BOOT DEVICE -->
<receiver android:name="ishpia.droid.activities.services.boot.bootreceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</receiver>

<!-- SERVICE -->
<service android:name="ishpia.droid.activities.services.order.postdervice" android:exported="false" />
<service android:name="ishpia.droid.activities.services.order.orderservice" android:exported="false" />
<service android:name="ishpia.droid.activities.services.periodic.periodicservice" android:exported="false" />

但是它产生了一个新问题,因为在某些实际设备中(根本没有,只有少数几个型号)发生了错误:


Fatal Exception: java.lang.RuntimeException: Unable to instantiate receiver ishpia.droid.activities.services.boot.bootreceiver: java.lang.ClassNotFoundException: Didn't find class "ishpia.droid.activities.services.boot.bootreceiver" on path: DexPathList[[zip file "/data/app/com.bergmannsoft.aprepara-x12fO8j-m_szPmi4Kc9Kyg==/base.apk"],nativeLibraryDirectories=[/data/app/com.bergmannsoft.aprepara-x12fO8j-m_szPmi4Kc9Kyg==/lib/arm, /data/app/com.bergmannsoft.aprepara-x12fO8j-m_szPmi4Kc9Kyg==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3374)
       at android.app.ActivityThread.-wrap18(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:7000)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

显然,某些设备找不到BootReceiver类。

测试B(失败):

将名称替换为Manifest.xml中的类,在Android版本6以外的版本(7,8和9)中有效。实际上,无法理解为什么错误仅在版本6中发生。

<!-- BOOT DEVICE -->
<receiver android:name="Ishpia.Droid.Activities.Services.Boot.Bootreceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
..
</receiver>

测试N(暂时可以):

这是我为我的应用找到的最佳解决方案。

从Manifest.xml中删除所有服务和接收者,因此:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          xmlns:tools="http://schemas.android.com/tools"
          tools:ignore="GoogleAppIndexingWarning"
          android:versionCode="152" 
          android:versionName="3.2" 
          package="com.bergmannsoft.aprepara" 
          android:installLocation="auto">
    <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="27" />
  <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <!-- USER PERMISSION-->
  <uses-permission android:name="android.permission.INTERNET" android:required="true" />
  <uses-permission android:name="android.permission.CAMERA" android:required="true" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:required="true" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="true" />
  <uses-permission android:name="android.permission.CALL_PHONE" android:required="true" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" android:required="true" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" android:required="true" />
  <uses-permission android:name="android.permission.READ_USER_DICTIONARY" android:required="true" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
  <!-- PERMISSION-->
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <uses-permission android:name="com.bergmannsoft.aprepara.permission.MAPS_RECEIVE" android:required="true" />  
  <uses-permission android:name="com.bergmannsoft.aprepara.permission.C2D_MESSAGE" />
  <permission android:name="com.bergmannsoft.aprepara.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <permission android:name="com.bergmannsoft.aprepara.permission.C2D_MESSAGE" android:protectionLevel="signature" />
  <!-- APLICATION -->
    <application android:allowBackup="false" android:label="@string/app_title" android:icon="@mipmap/icon" android:roundIcon="@mipmap/icon_round" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBarNotExtended">
    <!-- Put your Google Maps V2 API Key here. -->
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXXXXXXXXXXXXX" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <!-- FCM/GCM -->
    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
    <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/background" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="${applicationId}" />
      </intent-filter>
    </receiver>
    <!-- FILE PROVIDER -->
    <provider android:name="android.support.v4.content.FileProvider" android:grantUriPermissions="true" android:exported="false" android:authorities="${applicationId}.fileprovider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths" />
    </provider>
  </application>
</manifest>

并将属性作为属性直接插入Xamarin类中(在编译期间xamarin将插入Manifest之后)。

广播接收器

namespace Ishpia.Droid.Activities.Services.Boot
{
    [BroadcastReceiver(Enabled = true, Exported = false, Permission = "android.permission.RECEIVE_BOOT_COMPLETED")]
    [IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.LowPriority, Categories = new[] { Intent.CategoryDefault })]
    public class BootReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
            Intent i = new Intent(context, typeof(SplashActivity));
            i.AddFlags(ActivityFlags.NewTask);
            context.StartActivity(i);
        }
    }
}

OrderService

namespace Ishpia.Droid.Activities.Services.Order
{
    [Service (Exported = false)]
    public class OrderService : IntentService
    {
        ...
    }
}

PostService

namespace Ishpia.Droid.Activities.Services.Order
{
    [Service(Exported = false)]
    class PostService : IntentService
    {
    ..
    }
}

PeriodicService

namespace Ishpia.Droid.Activities.Services.Periodic
{
    [Service(Exported = false)]
    class PeriodicService : Service
    {
    ...
    }
}

Xamarin将在编译后导出Manifest.xml:

        <service
            android:name="md556d51780b7ddda82c5xxxxxxxxxxxxx.RegistrationIntentService"
            android:exported="false" />

        <service
            android:name="md527cd63edec29ae2b7xxxxxxxxxxxxx.PeriodicService"
            android:exported="false" />

        <service
            android:name="md51a4cc6308c061c7f0xxxxxxxxxxxxx.OrderService"
            android:exported="false" />

        <service
            android:name="md51a4cc6308c061c7fxxxxxxxxxxxxx.PostService"
            android:exported="false" />

        <receiver
            android:name="md53c9e18cf96d129xxxxxxxxxxxxx.BootReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
            android:enabled="true"
            android:exported="false">

            <intent-filter
                android:priority="-1000">

                <action
                    android:name="android.intent.action.BOOT_COMPLETED" />

                <category
                    android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

这些是我的应用程序中为解决正在发生的问题而采取的步骤,我认为这不是一个简单的要解决的问题。我可能缺乏Xamarin的经验,但是我正在提出解决方案,以防我可以帮助其他人。

答案 2 :(得分:0)

我已经花了好几个小时在一个可以在Android 8+上正常运行的应用程序上狂奔,但拒绝安装任何低于该版本的应用程序。

android lint实用程序也没有使我变得更明智,因为它报告没有任何错误。

最后,问题似乎是一个以大写字母开头的活动的名称。

可悲的是,只有Android 7.0模拟器为我提供了不错的错误描述(指向清单文件和属性中的行)

Android 6.0模拟器给了我一个通用错误,就像OP中提到的那样。