Search code examples
angularcordovaionic-frameworkbuildionic-native

Ionic Cordova build always use last version of androidx.appcompat:appcompatn and failed


I am running ionic cordova build android and failing.

After two days of research, I tried several approaches, and finally I found the problem, but I can't find the solution.

I use cordova platform 10.1.0, which generates project.properties like this

target=android-30
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=androidx.annotation:annotation:1.1.0
cordova.system.library.2=androidx.legacy:legacy-support-v4:1.+
cordova.system.library.3=androidx.appcompat:appcompat:1.+

that works fine until two days ago, when built in dashboard ionic get failed.

I found that androidx.appcompat:appcompat:1.+ always use last version androidx.appcompat:appcompat:1.4.0-beta01. and cordova.cmd build android command throws me the following error

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.appcompat:appcompat:1.4.0-beta01.
     AAR metadata file: C:\Users\YOAN\.gradle\caches\transforms-3\cf625c79807b9ffa78b701a3a960597e\transformed\appcompat-1.4.0-beta01\META-INF\com\android\build\gr
adle\aar-metadata.properties.

If I change androidx.appcompat:appcompat:1.+ to androidx.appcompat:appcompat:1.3.1 , its works, also if I remove entire line works too, but build only locally, if I deploy to dashboardionicframework ci/cd, get failed again because that changes do not reflect in CI CD build.

I tried adding <framework src="androidx.appcompat:appcompat:1.3.0" /> to config.xml, to force to load appcompat specific version, but that does not work.

also I added <framework custom="true" src="config-extras.gradle" type="gradleReference" /> to config.xml to put extra gradle config like this :

allprojects {
  repositories {
      configurations.all {
          resolutionStrategy {
               force 'androidx.appcompat:appcompat:1.3.1'
          }
      }
  } 
}

to force to use specific version, but that does not work.

I need to override project.properties specific value, or at least force to use specific version I need.


Solution

  • This issue is related to androidx.appcompat:appcompat 1.4.0-beta01 released on September 29, 2021.

    As plugin.xml defines ANDROIDX_VERSION as major version 1 (1.+), 1.4.0-beta01 was used instead of 1.3.0. Unfortunately you cannot simply use cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.3.+ to overwrite the value, as the same version would be used for androidx.legacy:legacy-support-v4 which exists as version 1.0.0 only.

    I successfully used cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION="[1.0, 1.4[" to get my builds fixed.