Android : INSTALL_PARSE_FAILED_MANIFEST_MALFORMED when update targetSdkVersion to 31 or more (android 12)

ปัจจุบันตอนนี้ Android 12 (API version 31 and above) ออกมาใช้งานจริงแล้ว เมื่อเราทำการอัพเดท Android App โดยการกำหนด “targetSdkVersion” = 31 และปรับค่า compileSdkVersion = 31 แล้วทดลองรันโปรแกรม ปรากฎว่าเกิด error message ดังนี้

The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

Installation failed due to: ‘INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1118761760.tmp/base.apk (at Binary XML file line #97)

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

ารแก้ไขปัญหา

ให้เข้าไปแก้ไขไฟล์ AndroidManifest.xml ในส่วนของ <activity …. </activity>. โดยการเพิ่ม

android:exported="true"

ดังตัวอย่าง

<activity
     android:name=".MainActivity"
     android:exported="true"
     android:launchMode="singleTop"
     android:theme="@style/LaunchTheme"
 </activity>

หมายเหตุ

ตัว Android Studio เองก็แสดงสัญลักษณ์สีแดงขึ้นตรง <activity> ….. </activity> และจะมี hint แนะนำว่าให้เพิ่ม android:exported=”true” เมื่อเรากดตามก็จะเพิ่มให้เองโดยอัตโนมัติ

You may also like...