由于某个Android项目最近需要开发新的需求,在调试过程中出现错误:

The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

初步判断是AndroidManifest.xml文件内容有问题,经检查和询问Google,网络上有记录的引发此类问题的原因有以下几种。

解决过程

  1. android 12需要加上android:exported

    <!-- 闪屏页 -->
    <activity
    android:name=".MainActivity"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme"
    android:exported="true"
    tools:ignore="AppLinkUrlError">

    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <action android:name="android.intent.action.VIEW" />
    </intent-filter>

    </activity>

    然而这个方法并不适用于我的项目,因为本身也是加上了这个配置的。

  2. 查看更多报错信息

    通过检查更多的报错信息,发现有以下信息被忽略了:

    Failed to commit install session 543156194 with command package install-commit 543156194. Error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl543156194.tmp/base.apk (at Binary XML file line #416): leakcanary.internal.activity.LeakLauncherActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

    看到这个提示之后,猜测可能是某些依赖的版本不兼容当前版本了,检查之后将build.gradle debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'依赖升级到 debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'问题解决。

END

记录一下此次解决问题的过程,遇到问题不要猴急,多看报错信息,就能找到很多线索。

为了解决这次遇到的问题,查询Google都浪费了不少时间。