Project builds successfully on local PC in Android Studio after upgrade to Gradle 7 but not in Gitlab pipeline.
Gradle 7.0.2 requires Java 11.
The error message in Gitlab pipeline is
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
ingradle.properties
.
(check your gradle version by executing the below command on the local machine from the project directory at the command prompt )
.\gradlew --version
.gitlab-ci.yml: The original complete .gitlab-ci.yml script is described in this post from 2018 which works with Java 1.8 (not with Java 11) AND with gradle 4 (not with gradle 7) on Gitlab: https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/
on local pc in Android Studio: Upgrading from Java 1.8 to 11
On the local pc in Android Studio upgrading from Java 1.8 to 11 required 3 steps(and a reboot):
Step 1: adjusting the Gradle setting in Android Studio to Java 11 or higher
(Arctic Fox 2020.3.1 Patch 4: File->Settings->Build,Execution,Deployment->Build Tools->Gradle->Gradle JDK)
Step 2: updating the JAVA_HOME variable (Windows "Edit the System Environment Variables"[
Set the JAVA_HOME variable to the same as in Android Studio
Step 3: update build.gradle from JavaVersion.VERSION_1_8 to JavaVersion.VERSION_11
Change it in Menu Project Structure also by selecting Open (in Lightbulb or on top right)
Reboot.
.gitlab-ci.yml : Upgrading from Java 1.8 to 11
The original .gitlab-ci.yml produced the below error with Gradle 7.0.2 when the code built on the new gradle version 7.0.2 was pushed to gitlab:
1st error with original gitlab.ci.yaml
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
ingradle.properties
.
Changing the image in .gitlab-ci.yml on line 1 from
image: openjdk:8-jdk
To
image: openjdk:11-jdk
produced another error:
$ echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) at com.android.repository.api.SchemaModule.(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 5 more Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1
I have spent a lot of time on this issue.
Any suggestions ?