airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
197 stars 11 forks source link

Building issue with AIR 51.0.1.3 and Gradle #3297

Open yvant opened 3 weeks ago

yvant commented 3 weeks ago

I tried to update to AIR 51.0.1.3 from AIR 50.2.5.1, using FlashDevelop. I'm using openjdk version "11.0.22" 2024-01-16.

Here's the error message I got;

Warning: packagedDependency play-services-appset-16.0.2.jar used by more than one ANE. Ignoring this entry
NOTE: Multiple Android build-tools folders exist, choosing the latest version (35.0.0 rc2) for packaging
NOTE: targets later than Android 33 need Gradle Plugin versions of 8 or more. Adjusting to 8.1.1
unexpected failure: Unable to run java: com.adobe.air.ADTException: gradle tool failed:
FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Yvan\AppData\Local\Temp\35f0357d-f443-4b36-8eff-a1a63b9f3851\androidx.activity\build.gradle' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
      Your current JDK is located in C:\Program Files\Java\jdk-11
      You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

java.io.IOException: Unable to run java: com.adobe.air.ADTException: gradle tool failed:
FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Yvan\AppData\Local\Temp\35f0357d-f443-4b36-8eff-a1a63b9f3851\androidx.activity\build.gradle' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
      Your current JDK is located in C:\Program Files\Java\jdk-11
      You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

        at com.adobe.air.apk.AABOutputStream.buildGradle(AABOutputStream.java)
        at com.adobe.air.apk.AABPackager.renameOutput(AABPackager.java)
        at com.adobe.air.ApplicationPackager.createPackage(ApplicationPackager.java)
        at com.adobe.air.apk.AABPackager.createPackage(AABPackager.java)
        at com.adobe.air.ADT.parseArgsAndGo(ADT.java)
        at com.adobe.air.ADT.run(ADT.java)
        at com.adobe.air.ADT.main(ADT.java)

I'll try updating to java 17. But is it a requirement for AIR 51? Won't it bring additional issues?

ajwfrost commented 3 weeks ago

Hi

The requirement for Java 17 actually comes from the Android Gradle Plugin, and this version of AGP is required because of the compile / build tools:

NOTE: Multiple Android build-tools folders exist, choosing the latest version (35.0.0 rc2) for packaging

Basically, the AIR SDK looks in your Android SDK folder to see what build tools are available, and always selects the latest ones.

We are looking at adjusting things so that either the tools version could be configurable, or so that we ignore the need for AGP 8.x if we're running on Java 11 still (there will be a warning emitted by AGP 7.x but - currently at least - it should still work).

thanks

yvant commented 3 weeks ago

Thanks for the quick answer. So my best option is to upgrade to java 17? I'm not really at ease with all the android environment / gradle etc.

ajwfrost commented 3 weeks ago

Yes, the two choices currently would be:

yvant commented 3 weeks ago

Thanks!

yvant commented 2 weeks ago

So in the end I updated to openjdk version "17.0.11" 2024-04-16 OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9) to be able to build and the publish was successful. However, I recently got a mail from Google:

Upgrade your game to a newer com.google.android.play:core SDK version

com.google.android.play:core has added this note for core:1.8.3:

Update your Play Core Maven dependency to an Android 14 compatible version! Your current Play Core library is incompatible with targetSdkVersion 34 (Android 14), which introduces a backwards-incompatible change to broadcast receivers to improve user security. As a reminder, from August 31, Google Play requires all new app releases to target Android 14. Update to the latest Play Core library version dependency to avoid app crashes: https://developer.android.com/guide/playcore#playcore-migration

1 - What do I need to do to prevent this? 2 - Isn't it better to stick to java 11 and downgrade v34.x and v35.x Android SDK versions? 3 - Why was it ok to keep v34.x and v35.x Android SDK in AIR 50.x?

ajwfrost commented 2 weeks ago

That's an interesting message and makes our choices a little more complex...

Just to answer the questions (well, the second/third ones): ADT has always looked at the available "build tools" folders that are in the Android SDK location, and picks up the last one. That "Multiple Android build-tools folders exist" came from the original Adobe code - but this is probably made more problematic by the fact we use the tools in this folder for the Gradle building. And this is where it then ends up with problems.

So our planned workarounds were: 1) If someone is running with Java 11 and we don't have a Java 17 installation in a known location, then we could ignore the suggested update to AGP 8.x, which means that we would be able to build the project even though there would be a warning about using compile version 34 using AGP 7.x.... 2) With an updated set of options in the App Descriptor file, we could allow someone to specify the build tools version to use, which means that you could say your app needs to compile with v33, and we'd then know that AGP7.x / Java 11 is fine to use (and there would be no warnings etc).

The challenge with what you're trying there is that approach 1 wouldn't work: we could build it fine with the warning from AGP, but you'd still hit this issue with the Play Core Maven dependency (I think). And that's then because of the build tools being v34, which we can't change without approach 2 (or see below...)

But to answer your first question .. ultimately you need to be building this app using compile SDK and target SDK settings of v33. For the targetSDK, that's something you can have in your app descriptor file (if you don't already?), so something to add to your manifestAdditions section such as: <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>

To change the compile SDK version, you would need to ensure we don't find any of the other build tools. So e.g. if I go in Windows to %localappdata%\android\sdk\build-tools I can see folders 31.00, 33.0.1, 33.0.2, 34.0.0 etc. If you remove the ones from 34 onwards (via Android SDK Manager) it should limit the compile version to 33. Alternatively if you want to just hide them from ADT, you can rename the source.properties file that's inside each of the folders, cos that's what we inspect to find out the version details...

Hope that helps. We'll look at getting out a build with the "approach 1" in it, but are also going to be pushing out 51.1 soon which will have "approach 2" that should give more flexibility to it all...

yvant commented 2 weeks ago

Thanks for the detailled answer. I'll try to set up the targetSdkVersion to , remove newer android sdk and publish it like that. Should I still use java 17? Or is java 11 a better choice then?

ajwfrost commented 2 weeks ago

Fingers crossed :-) At this point, it shouldn't really matter which Java version is used

yvant commented 2 weeks ago

Now that I thing about it, latest ANEs require <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="34"/>. How to handle this discrepancy?

ajwfrost commented 2 weeks ago

Potentially there's a difference between the "compileSdk", "targetSdk" and build tools settings... which may mean that this could still be handled with an older version of the Android platform. But it perhaps depends on the exact requirements.

You mention here that the latest ANEs have a targetSdkVersion requirement of 34, but your other ANE gave an error: Your current Play Core library is incompatible with targetSdkVersion 34

So probably you just need to update that one...?

Ultimately, as per the Google message, everything should start switching to Android 14 = API 34, for which you're meant to use an Android Gradle Plug-in of version 8 or higher, requiring Java 17.. if you do have things that are not compatible with those then - if you're pushing out via the Play Store - you may need to get updates for them...

thanks