Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
110 stars 140 forks source link

Cordova build android failed: Execution failed for task ':app:checkDebugAarMetadata'. #369

Closed itpixelz closed 2 years ago

itpixelz commented 2 years ago

In my Cordova app, without this pushwoosh-cordova-plugin, the app build is successful but when I add this plugin. When trying to build the Cordova app, it fails with the following error.

> Task :app:checkDebugAarMetadata FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.work:work-runtime:2.7.1.
     AAR metadata file: /Users/u/.gradle/caches/transforms-3/73e09204760ea4755dc4d86cf2bf4d4f/transformed/work-runtime-2.7.1/META-INF/com/android/build/gradle/aar-metadata.properties.

Here is package.json file

{
  "name": "io.cordova.hellocordova",
  "displayName": "HelloCordova",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "ecosystem:cordova"
  ],
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "devDependencies": {
    "cordova-android": "^10.1.2",
    "cordova-plugin-inappbrowser": "^5.0.0",
    "cordova-plugin-splashscreen": "^6.0.1",
    "cordova-plugin-statusbar": "^3.0.0",
    "pushwoosh-cordova-plugin": "^8.3.4"
  },
  "cordova": {
    "platforms": [
      "android"
    ],
    "plugins": {
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "pushwoosh-cordova-plugin": {
        "LOG_LEVEL": "DEBUG",
        "IOS_FOREGROUND_ALERT_TYPE": "NONE",
        "ANDROID_FOREGROUND_PUSH": "false"
      }
    }
  }
}
Techsorcist commented 2 years ago

Hi @itpixelz This error usually arises when you decide to set your target SDK to target android 12 (SDK 31). To fix the error, you need to add this line android:exported="true" to the <activity> (MainActivity) in the AndroidManifest.xml.

itpixelz commented 2 years ago

Thank you so much for your response @Techsorcist. I have checked my file AndroidManifest.xml and it is already set android:exported="true" to the <activity>. Here is the file AndroidManifest.xml.

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data android:name="com.pushwoosh.log_level" android:value="DEBUG" />
        <meta-data android:name="com.pushwoosh.foreground_push" android:value="false" />
        <meta-data android:name="com.pushwoosh.notification_service_extension" android:value="com.pushwoosh.plugin.pushnotifications.PushwooshNotificationServiceExtension" />
        <meta-data android:name="com.pushwoosh.internal.plugin_provider" android:value="com.pushwoosh.plugin.internal.PhonegapPluginProvider" />
    </application>
</manifest>
wfhm commented 2 years ago

@itpixelz The latest versions of the plugin are dependent on androidx.work:work-runtime:2.7.+ library, and those versions require targeting Android API 31 or higher. To fix the build issue, you should add the following line to your config.xml:

<preference name="android-targetSdkVersion" value="31" />