[Android] AndroidStudio reports an error when running on the phone: Installation failed due to: 'null'

I created a new Android project. I just wanted to run it on my phone, but found that it could not be installed. The error was reported as follows:

Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

List of apks:
[0] 'app/build/outputs/apk/debug/app-debug.apk'
Installation failed due to: 'null'

I just finished the build and no error was reported, and the package name is definitely not used before.

I tried clean+rebuild, but it didn't work.

Build an apk and install it on your phone using adb, and find the following information:

Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]。

After searching, it was said that in Android 11 and below, when declaring an activity, service or broadcast receiver in AndroidManifest, you did not explicitly declare android:exported. Since the default value is exported=true, you only need to declare exported=false when you don't want it to be exposed to the outside world.

However, there are changes in Android 12. Explicit declaration of the exporting application that sets SDK API 31 (android 12) as the target sdk on Android 12 devices The export must be explicitly declared in the component, such as the Activity that declares the intent-filter. Otherwise, an error will occur and the installation will fail.

Solution: add

android:exported="true"
  <activity 
    android:name=".MainActivity"
    android:exported="true">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

This sharing is over.

Guess you like

Origin blog.csdn.net/u010055598/article/details/133312236