Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Gradle plugin 7.0.0+ requires Java 11 to build app #2067

Closed
egorikftp opened this issue Dec 4, 2020 · 25 comments
Closed

Android Gradle plugin 7.0.0+ requires Java 11 to build app #2067

egorikftp opened this issue Dec 4, 2020 · 25 comments
Labels
build Related to App Center's Build service feature request New feature request reviewed-DRI Reviewed by DRI

Comments

@egorikftp
Copy link

Describe the solution you'd like
To support appcenter build with the latest gradle plugin, could you please add Java 11?

Current error code:

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     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`.

Additional context
https://android-developers.googleblog.com/2020/12/announcing-android-gradle-plugin.html

@egorikftp egorikftp added the feature request New feature request label Dec 4, 2020
@DmitriyKirakosyan DmitriyKirakosyan added the build Related to App Center's Build service label Dec 27, 2020
@harry248
Copy link

We can't switch to Android Studio Arctic Fox because of this, which ist required if you want to use Jetpack Compose. Would be nice to get some information about when the update is going to happen.

@harry248
Copy link

We were able to work around the problem by adding a pre-build script (appcenter-pre-build.sh, put next to the module level build gradle file) with the following content:

#!/usr/bin/env bash
(echo ""; echo "org.gradle.java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/") >> $APPCENTER_SOURCE_DIRECTORY/gradle.properties

Don't forget to manually trigger "Save & Build" in the build configuration afterwards.

Thanks to Anvesh from Appcenter for pointing us in the right direction.

@mihailo-popovic96 mihailo-popovic96 added the reviewed-DRI Reviewed by DRI label Mar 17, 2021
@johnnylambada
Copy link

I couldn't get harry248's solution to work. However it turns out that if you set the JAVA_HOME environment variable to /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/ in the appcenter config for that build it has the same effect.

@ghost ghost closed this as completed Jun 16, 2021
@aabiryukov
Copy link

Can be used pre-defined environment variable: JAVA_HOME_11_X64
Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

@SharpMobileCode
Copy link

Can be used pre-defined environment variable: JAVA_HOME_11_X64
Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

Thank you for this info! Creating a JAVA_HOME environment variable with that value worked for me.

@stanchostanchev
Copy link

Can be used pre-defined environment variable: JAVA_HOME_11_X64
Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration
image
All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

Thank you for this info! Creating a JAVA_HOME environment variable with that value worked for me.

Absolutely - this worked for me also

@shashi-appgolive
Copy link

What is the format for value for custom variable ?

Will this work ? or the values should be bounded with $()

app_center_env

@NasarIqbal
Copy link

Can be used pre-defined environment variable: JAVA_HOME_11_X64 Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

Thanks this works for me.

@aber-peak
Copy link

I'm attempting this solution to build an Android project using Gradle, but it seems like the agent can't find JAVA_HOME_11_X64.

Here's the details of the agent:

Agent name: 'Hosted Agent'
Agent machine name: 'Mac-1646855858279'
Current agent version: '2.200.2'
##[group]Operating System
Mac OS X
10.15.7
19H1715
##[endgroup]
##[group]Virtual Environment
Environment: macos-10.15
Version: 20220219.1
Included Software: https://github.com/actions/virtual-environments/blob/macOS-10.15/20220219.1/images/macos/macos-10.15-Readme.md
Image Release: https://github.com/actions/virtual-environments/releases/tag/macOS-10.15%2F20220219.1
##[endgroup]
##[group]Virtual Environment Provisioner
1.0.0.0-main-20220301-2
##[endgroup]

Later on, we see the failure to find the path:

[command]/Users/runner/work/1/s/app/gradlew -DAPPCENTER_KEYSTORE_PASSWORD=*** -DMOBILECENTER_KEYSTORE_PASSWORD=*** -DAPPCENTER_KEYSTORE_FILE_ID=***.app.keystore -DMOBILECENTER_KEYSTORE_FILE_ID=***.app.keystore -DAPPCENTER_KEY_ALIAS=*** -DMOBILECENTER_KEY_ALIAS=*** -DAPPCENTER_KEY_PASSWORD=*** -DMOBILECENTER_KEY_PASSWORD=*** -DAPPCENTER_BUILD_VERSION=5 -DMOBILECENTER_BUILD_VERSION=5 -p app clean :app:assembleStagingFlavorRelease

ERROR: JAVA_HOME is set to an invalid directory:  /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-101/x64/Contents/Home/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Error: /Users/runner/work/1/s/app/gradlew failed with return code: 1

Is it possible that the agent is misconfiguring this environment variable?

@logicallayer
Copy link

I'm attempting this solution to build an Android project using Gradle, but it seems like the agent can't find JAVA_HOME_11_X64.

Here's the details of the agent:

Agent name: 'Hosted Agent'
Agent machine name: 'Mac-1646855858279'
Current agent version: '2.200.2'
##[group]Operating System
Mac OS X
10.15.7
19H1715
##[endgroup]
##[group]Virtual Environment
Environment: macos-10.15
Version: 20220219.1
Included Software: https://github.com/actions/virtual-environments/blob/macOS-10.15/20220219.1/images/macos/macos-10.15-Readme.md
Image Release: https://github.com/actions/virtual-environments/releases/tag/macOS-10.15%2F20220219.1
##[endgroup]
##[group]Virtual Environment Provisioner
1.0.0.0-main-20220301-2
##[endgroup]

Later on, we see the failure to find the path:

[command]/Users/runner/work/1/s/app/gradlew -DAPPCENTER_KEYSTORE_PASSWORD=*** -DMOBILECENTER_KEYSTORE_PASSWORD=*** -DAPPCENTER_KEYSTORE_FILE_ID=***.app.keystore -DMOBILECENTER_KEYSTORE_FILE_ID=***.app.keystore -DAPPCENTER_KEY_ALIAS=*** -DMOBILECENTER_KEY_ALIAS=*** -DAPPCENTER_KEY_PASSWORD=*** -DMOBILECENTER_KEY_PASSWORD=*** -DAPPCENTER_BUILD_VERSION=5 -DMOBILECENTER_BUILD_VERSION=5 -p app clean :app:assembleStagingFlavorRelease

ERROR: JAVA_HOME is set to an invalid directory:  /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-101/x64/Contents/Home/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Error: /Users/runner/work/1/s/app/gradlew failed with return code: 1

Is it possible that the agent is misconfiguring this environment variable?

worked for me.

name: JAVA_HOME
value: $(JAVA_HOME_11_X64)

@praharshbhatt
Copy link

I'm attempting this solution to build an Android project using Gradle, but it seems like the agent can't find JAVA_HOME_11_X64.

Here's the details of the agent:

Agent name: 'Hosted Agent'
Agent machine name: 'Mac-1646855858279'
Current agent version: '2.200.2'
##[group]Operating System
Mac OS X
10.15.7
19H1715
##[endgroup]
##[group]Virtual Environment
Environment: macos-10.15
Version: 20220219.1
Included Software: https://github.com/actions/virtual-environments/blob/macOS-10.15/20220219.1/images/macos/macos-10.15-Readme.md
Image Release: https://github.com/actions/virtual-environments/releases/tag/macOS-10.15%2F20220219.1
##[endgroup]
##[group]Virtual Environment Provisioner
1.0.0.0-main-20220301-2
##[endgroup]

Later on, we see the failure to find the path:

[command]/Users/runner/work/1/s/app/gradlew -DAPPCENTER_KEYSTORE_PASSWORD=*** -DMOBILECENTER_KEYSTORE_PASSWORD=*** -DAPPCENTER_KEYSTORE_FILE_ID=***.app.keystore -DMOBILECENTER_KEYSTORE_FILE_ID=***.app.keystore -DAPPCENTER_KEY_ALIAS=*** -DMOBILECENTER_KEY_ALIAS=*** -DAPPCENTER_KEY_PASSWORD=*** -DMOBILECENTER_KEY_PASSWORD=*** -DAPPCENTER_BUILD_VERSION=5 -DMOBILECENTER_BUILD_VERSION=5 -p app clean :app:assembleStagingFlavorRelease

ERROR: JAVA_HOME is set to an invalid directory:  /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-101/x64/Contents/Home/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Error: /Users/runner/work/1/s/app/gradlew failed with return code: 1

Is it possible that the agent is misconfiguring this environment variable?

Same with me.
echo "JAVA_HOME: $(JAVA_HOME)"
gives
JAVA_HOME: /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-101/x64/Contents/Home/

Starting: Build Android Bundle
==============================================================================
Task         : Flutter Build Task
Description  : Build a Flutter application project.
Version      : 0.3.1
Author       : Hey24sheep
Help         : [More Information](https://github.com/hey24sheep/azure-flutter-tasks)
==============================================================================
/Users/runner/hostedtoolcache/Flutter/2.10.5-stable/macos/flutter/bin/flutter build appbundle --build-name=3.2.4 --build-number=5879 --flavor=sparrow --target=lib/whitelabels/main/sparrow_main.dart --release

💪 Building with sound null safety 💪

Running Gradle task 'bundleSparrowRelease'...                   

ERROR: JAVA_HOME is set to an invalid directory: $(JAVA_HOME_11_X64)

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Running Gradle task 'bundleSparrowRelease'...                      386ms
Gradle task bundleSparrowRelease failed with exit code 1
##[error]Error: The process '/Users/runner/hostedtoolcache/Flutter/2.10.5-stable/macos/flutter/bin/flutter' failed with exit code 1
Finishing: Build Android Bundle

@praharshbhatt
Copy link

Update: I got it working by adding:

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

As regarded by this answer.

@alexstoyanov
Copy link

@praharshbhatt Where did you put that snippet?

@praharshbhatt
Copy link

@praharshbhatt Where did you put that snippet?

in the .yml build file

@gazoakley
Copy link

I'm using App Center to run a React Native build for Android - I also had to set PATH or the build failed with the error above:

Name Value
JAVA_HOME $(JAVA_HOME_11_X64)
PATH $(JAVA_HOME_11_X64)/bin;$(PATH)

@dhiroofmc
Copy link

dhiroofmc commented Aug 18, 2022

Can be used pre-defined environment variable: JAVA_HOME_11_X64
Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration
image
All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

Thank you for this info! Creating a JAVA_HOME environment variable with that value worked for me.

Getting another issue after adding JAVA_HOME in AppCenter, Same code working in my machine

+ cp /Users/runner/work/1/s/android/app/firebase/google-services.json_AL-7781 /Users/runner/work/1/s/android/app/google-services.json cp: /Users/runner/work/1/s/android/app/firebase/google-services.json_AL-7781: No such file or directory ##[error]The process '/bin/bash' failed with exit code 1 ##[error]Bash failed with error: The process '/bin/bash' failed with exit code 1 ##[section]Finishing: Pre Build Script ##[section]Starting: Checkout fmc-alpha-fe@AL-7781 to s

@stanchostanchev
Copy link

stanchostanchev commented Oct 11, 2022 via email

@Aszurar
Copy link

Aszurar commented Nov 7, 2022

Can be used pre-defined environment variable: JAVA_HOME_11_X64 Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

Thanks soooo muuchh!!!! worked here!

@rvera
Copy link

rvera commented Nov 17, 2022

I can't seem to get this to work with my react native android project, I get

ERROR: JAVA_HOME is set to an invalid directory: /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.17-8/x64/Contents/Home/ 

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

@stanchostanchev
Copy link

stanchostanchev commented Nov 18, 2022 via email

@rvera
Copy link

rvera commented Nov 18, 2022

haha I mean that's fair, but I'm using appcenter constants here. So JAVA_HOME_11_X64 would be set but the actual path would leads to nothing? Any way I can force the installation of the Java 11 then?

@glennweb
Copy link

Worked for me in my React Native project. My change was not related to targeting Grade 7. But just more the fact that I was targeting Android SDK 31.

Can be used pre-defined environment variable: JAVA_HOME_11_X64 Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

@danieltvaz
Copy link

danieltvaz commented Dec 16, 2022

Can be used pre-defined environment variable: JAVA_HOME_11_X64 Set JAVA_HOME to $(JAVA_HOME_11_X64) in the build configuration

image

All available java home variables are listed here: https://github.com/actions/virtual-environments/blob/macOS-10.15/20210718.2/images/macos/macos-10.15-Readme.md#Java

This workaround makes my project finally build. BUT, when I run the builded apk on a device (or simulator) it crashes just at startup.

Anyone having this issue?

edit: my project started to get problems when building after i changed sdk target and compile version to 31

@manarfalah
Copy link

I can't seem to get this to work with my react native android project, I get

ERROR: JAVA_HOME is set to an invalid directory: /Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.17-8/x64/Contents/Home/ 

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

did you find solution for this ? same problem here

@harrymash2006
Copy link

Not able to set this: $(JAVA_HOME_11_X64) value in environment variable

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to App Center's Build service feature request New feature request reviewed-DRI Reviewed by DRI
Projects
None yet
Development

No branches or pull requests