microsoft / appcenter

Central repository for App Center open source resources and planning.
https://appcenter.ms
Creative Commons Attribution 4.0 International
1.01k stars 223 forks source link

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

Closed egorikftp closed 3 years ago

egorikftp commented 3 years ago

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

harry248 commented 3 years ago

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 commented 3 years ago

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.

johnnylambada commented 3 years ago

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.

aabiryukov commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

What is the format for value for custom variable ?

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

app_center_env
NasarIqbal commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Update: I got it working by adding:

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

As regarded by this answer.

alexstoyanov commented 2 years ago

@praharshbhatt Where did you put that snippet?

praharshbhatt commented 2 years ago

@praharshbhatt Where did you put that snippet?

in the .yml build file

gazoakley commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

project -> Build -> recent build -> click on the wrench

and after that follow the screen shot

you have to add JAVA_HOME environment var if it does not exists

see the attached screen shot


From: Praharsh Bhatt @.> Sent: Monday, May 16, 2022 8:31 PM To: microsoft/appcenter @.> Cc: Stancho Stanchev @.>; Comment @.> Subject: Re: [microsoft/appcenter] Android Gradle plugin 7.0.0+ requires Java 11 to build app (#2067)

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

@praharshbhatthttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpraharshbhatt&data=05%7C01%7Csstanchev%40objectsystems.com%7C9fd1b2064b8340d5b6e008da3761ebbb%7Cdb807785745c4049a031049b258214c0%7C0%7C0%7C637883190965235312%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=CLDr3OFeKpu2aEksNgHuHf%2BZWmgqrigXR0SKr1p3yhc%3D&reserved=0 Where did you put that snippet?

in the .yml build file

— Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fappcenter%2Fissues%2F2067%23issuecomment-1127945422&data=05%7C01%7Csstanchev%40objectsystems.com%7C9fd1b2064b8340d5b6e008da3761ebbb%7Cdb807785745c4049a031049b258214c0%7C0%7C0%7C637883190965235312%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BKsPZZKvArZt9Rm%2BnHHe9GM61NkRGyy9l7LdFt54D2c%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABYX6GH4654AGH74XHP5QP3VKKA7JANCNFSM4UNPOBPQ&data=05%7C01%7Csstanchev%40objectsystems.com%7C9fd1b2064b8340d5b6e008da3761ebbb%7Cdb807785745c4049a031049b258214c0%7C0%7C0%7C637883190965235312%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=s9%2BcxRPoL2k5QIr7R7kq8m2WuAMaUsdn8tYoMqs1ZAw%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

Aszurar commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

obviously the path that you set is not a path to jdk. This is what this message means.


From: Rodrigo Vera @.> Sent: Friday, November 18, 2022 1:33 AM To: microsoft/appcenter @.> Cc: Stancho Stanchev @.>; Comment @.> Subject: Re: [microsoft/appcenter] Android Gradle plugin 7.0.0+ requires Java 11 to build app (#2067)

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

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.

— Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fappcenter%2Fissues%2F2067%23issuecomment-1319348031&data=05%7C01%7Csstanchev%40objectsystems.com%7Cd559934963c0416ee8fe08dac8f41150%7Cdb807785745c4049a031049b258214c0%7C0%7C0%7C638043247837912196%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4AUk6hzvw0ZB%2BgvSZvx5L0QgQIF8ryghuZrm6dgVFBg%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABYX6GA5BKFIE6DFFY65QRLWI26CZANCNFSM4UNPOBPQ&data=05%7C01%7Csstanchev%40objectsystems.com%7Cd559934963c0416ee8fe08dac8f41150%7Cdb807785745c4049a031049b258214c0%7C0%7C0%7C638043247837912196%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Kd4DM4coxhVsZ8ZWsEyxWXaYCvT05i%2F1L4iwkJPGhUw%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

rvera commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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