apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

API Level set to 28 in cordova-android@11 #1603

Closed aaarichter closed 1 year ago

aaarichter commented 1 year ago

Bug Report

Problem

when installing the android platform with cordova platform add android@11 then the platforms/android/cdv-gradle-config.json sets the SDK version to 28

{
  "MIN_SDK_VERSION": 22,
  "SDK_VERSION": 28,
  "COMPILE_SDK_VERSION": null,
  "GRADLE_VERSION": "7.4.2",
  "MIN_BUILD_TOOLS_VERSION": "32.0.0",
  "AGP_VERSION": "7.2.1",
  "KOTLIN_VERSION": "1.5.21",
  "ANDROIDX_APP_COMPAT_VERSION": "1.4.2",
  "ANDROIDX_WEBKIT_VERSION": "1.4.0",
  "ANDROIDX_CORE_SPLASHSCREEN_VERSION": "1.0.0-rc01",
  "GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.3.10",
  "IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
  "IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false
}

What is expected to happen?

that the SDK_VERSION version is set to the latest, at least matching the MIN_BUILD_TOOLS_VERSION

What does actually happen?

Inside of CI/CD, gradle checks fail:

> Task :CordovaLib:extractReleaseAnnotations
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > 8 issues were found when checking AAR metadata:

       1.  Dependency 'androidx.appcompat:appcompat:1.4.2' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       2.  Dependency 'androidx.core:core-splashscreen:1.0.0-rc01' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       3.  Dependency 'androidx.appcompat:appcompat-resources:1.4.2' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       4.  Dependency 'androidx.emoji2:emoji2-views-helper:1.0.0' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       5.  Dependency 'androidx.emoji2:emoji2:1.0.0' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       6.  Dependency 'androidx.core:core:1.7.0' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       7.  Dependency 'androidx.lifecycle:lifecycle-process:2.4.0' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

       8.  Dependency 'androidx.lifecycle:lifecycle-runtime:2.4.0' requires libraries and applications that
           depend on it to compile against version 31 or later of the
           Android APIs.

           :app is currently compiled against android-28.

           Recommended action: Update this project to use a newer compileSdkVersion
           of at least 31, for example 32.

           Note that updating a library or application's compileSdkVersion (which
           allows newer APIs to be used) can be done separately from updating
           targetSdkVersion (which opts the app in to new runtime behavior) and
           minSdkVersion (which determines which devices the app can be installed
           on).

Information

Command or Code

in docker

npm install
cordova prepare android
cordova build android --release -- --keystore=./myRAzept_release_keystore.jks --storePassword="$APK_RELEASE_KEY_STORE_PASSWORD" --alias=myrazept --password="$APK_RELEASE_KEY_ALIAS_PASSWORD" --packageType=apk

Environment, Platform, Device

running in Gitlab CI

using beevelop/cordova docker image:

FROM beevelop/cordova

ENV ANDROID_HOME=$ANDROID_SDK_ROOT \
    CORDOVA_BUILD_TOOLS_VERSION=32.0.0

ENV PATH $PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/build-tools/$ANDROID_BUILD_TOOLS_VERSION:$ANT_HOME/bin:$MAVEN_HOME/bin:$GRADLE_HOME/bin

RUN while true; do echo 'y'; sleep 2; done | sdkmanager "build-tools;${CORDOVA_BUILD_TOOLS_VERSION}"

Version information

  "cordova": "^11.1.0"
  "cordova-android": "^11.0.0",
  "cordova-ios": "^6.3.0",
  "cordova-plugin-headercolor": "^1.0.0",
  "cordova-plugin-splashscreen": "^6.0.2",
  "cordova-plugin-statusbar": "^3.0.0"

Checklist

breautek commented 1 year ago

post your config.xml please

android-targetSdkVersion preference if set will influence/override the defaults. If you do not explicitly set it, then I'd scan your plugin's plugin.xml files to see if they set it (which they shouldn't but I see some plugins do)

aaarichter commented 1 year ago

@breautek

<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="${ANDROID_VERSION_CODE}" id="de.raps.myrazept" ios-CFBundleVersion="${IOS_BUNDLE_VERSION}" version="1.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>myRAzept</name>
    <author email="info@raps.com" href="https://www.raps.de/">
        RAPS GmbH &amp; Co. KG
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="https://*.k8s.incloud.de/*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="BackgroundColor" value="0xffffffff" />
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="StatusBarBackgroundColor" value="#ffffff" />
    <preference name="StatusBarDefaultScrollToTop" value="true" />
    <preference name="HeaderColor" value="#ffffff" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <icon src="res/icon/ios/Icon-1024.png" />
    <platform name="android">
        <icon density="mdpi" src="res/icon/android/mipmap-mdpi/ic_launcher.png" />
        <icon density="hdpi" src="res/icon/android/mipmap-hdpi/ic_launcher.png" />
        <icon density="xhdpi" src="res/icon/android/mipmap-xhdpi/ic_launcher.png" />
        <icon density="xxhdpi" src="res/icon/android/mipmap-xxhdpi/ic_launcher.png" />
        <icon density="xxxhdpi" src="res/icon/android/mipmap-xxxhdpi/ic_launcher.png" />
        <preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/screen/android/splash.png" />
        <preference name="SplashMaintainAspectRatio" value="true" />
        <preference name="StatusBarStyle" value="default" />
        <preference name="android-targetSdkVersion" value="28" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <icon height="20" src="res/icon/ios/Icon-20.png" width="20" />
        <icon height="29" src="res/icon/ios/Icon-29.png" width="29" />
        <icon height="40" src="res/icon/ios/Icon-40.png" width="40" />
        <icon height="58" src="res/icon/ios/Icon-58.png" width="58" />
        <icon height="60" src="res/icon/ios/Icon-60.png" width="60" />
        <icon height="76" src="res/icon/ios/Icon-76.png" width="76" />
        <icon height="80" src="res/icon/ios/Icon-80.png" width="80" />
        <icon height="87" src="res/icon/ios/Icon-87.png" width="87" />
        <icon height="120" src="res/icon/ios/Icon-120.png" width="120" />
        <icon height="152" src="res/icon/ios/Icon-152.png" width="152" />
        <icon height="167" src="res/icon/ios/Icon-167.png" width="167" />
        <icon height="180" src="res/icon/ios/Icon-180.png" width="180" />
        <icon height="1024" src="res/icon/ios/Icon-1024.png" width="1024" />
        <splash src="res/screen/ios/Default@2x~universal~anyany.png" />
        <config-file parent="ITSAppUsesNonExemptEncryption" target="*-Info.plist">
            <false />
        </config-file>
        <config-file mode="replace" parent="CFBundleDevelopmentRegion" target="*-Info.plist">
            <array>
                <string>de-DE</string>
            </array>
        </config-file>
        <config-file mode="replace" parent="CFBundleLocalizations" target="*-Info.plist">
            <array>
                <string>de</string>
            </array>
        </config-file>
        <preference name="StatusBarStyle" value="default" />
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

I removed the <plugin> and <engine> settings for testing purpose. With or without those tags, which were reflecting the versions from the package.json, the issue occurred.

breautek commented 1 year ago

There is

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

in your android's <platform> block. That's what's overriding the SDK_VERSION in the gradle config and causing the app to target & compile using SDK 28.

I'd recommend removing it to let it default to cordova-android default, which on version 11.x is API 32.

If there is a need to target API 31 for whatever reason, then I'd suggest doing:

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

This is so that the code will still compile using API 32, but your app will target API 31.

Note that targeting API 33 is not supported on cordova-android@11 (may or may not work, API 33 support is coming in our next release)

Please let me know if this solves your issue.

aaarichter commented 1 year ago

oh I totally missed this . thank you so much @breautek :octocat: - it worked perfectly.

I'm resolving this issue.

One more question. I uploaded the generate apk file to the play console and there is a warning saying that there isn't a file that discloses obfuscated code (R8/ProGuard). Is there a way to generate this disclosure file with cordova? Or should one migrate to the Android App Bundle format?

breautek commented 1 year ago

One more question. I uploaded the generate apk file to the play console and there is a warning saying that there isn't a file that discloses obfuscated code (R8/ProGuard). Is there a way to generate this disclosure file with cordova? Or should one migrate to the Android App Bundle format?

I'm not 100% sure what you're seeing but Cordova doesn't provide any ProGuard/R8 configuration. Mostly because it's not very useful since it will break Cordova. ProGuard (or R8) obfuscates the native code and mangles symbols so it makes it more difficult to reverse engineer, and to also to make the final product size smaller. But Cordova relies on finding classes/method names by strings so mangling symbols will break that mechanism.

If you want to use Proguard or R8, it must be configured in a way that it doesn't touch the Cordova classes or plugins.

I think Google will provide the warning when you upload your bundle because they recommend and want to encourage users to use it even if it's just to shrink the file size of your app. But yah, it will break Cordova unless if you tailed it specifically to not touch any cordova bits.

If you develop your own plugins, you could use Proguard/R8 on the plugin by creating an Android library with the cordova bits abstracted out for example, so that the bulk of the library is proguarded while the cordova interface to your plugin is not.

aaarichter commented 1 year ago

thanks again for your great reply @breautek