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

Add OpenJDK 21 #137

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ RUN apt-get update && apt-get -y install locales && \
ENV LANG=en_US.UTF-8

## Install dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \
openjdk-17-jdk \
openjdk-11-jdk \
openjdk-8-jdk \
git \
wget \
build-essential \
zlib1g-dev \
libssl-dev \
libreadline-dev \
unzip \
ssh \
# Fastlane plugins dependencies
# - fastlane-plugin-badge (curb)
libcurl4 libcurl4-openssl-dev \
# ruby-setup dependencies
libyaml-0-2 \
libgmp-dev \
file
RUN apt-get clean && \
apt-get update && \
apt-get install -y software-properties-common && \
apt-get update && apt-get install --no-install-recommends -y \
openjdk-21-jdk \
openjdk-17-jdk \
openjdk-11-jdk \
openjdk-8-jdk \
git \
wget \
build-essential \
zlib1g-dev \
libssl-dev \
libreadline-dev \
unzip \
ssh \
# Fastlane plugins dependencies
# - fastlane-plugin-badge (curb)
libcurl4 libcurl4-openssl-dev \
# ruby-setup dependencies
libyaml-0-2 \
libgmp-dev \
file

## Clean dependencies
RUN apt-get clean
Expand All @@ -47,10 +51,11 @@ ENV JENV_ROOT "$HOME/.jenv"
RUN git clone https://github.com/jenv/jenv.git $JENV_ROOT
ENV PATH "$PATH:$JENV_ROOT/bin"
RUN mkdir $JENV_ROOT/versions
ENV JDK_ROOT "/usr/lib/jvm/"
ENV JDK_ROOT "/usr/lib/jvm"
RUN jenv add ${JDK_ROOT}/java-8-openjdk-amd64
RUN jenv add ${JDK_ROOT}/java-11-openjdk-amd64
RUN jenv add ${JDK_ROOT}/java-17-openjdk-amd64
RUN jenv add ${JDK_ROOT}/java-21-openjdk-amd64
RUN echo 'export PATH="$JENV_ROOT/bin:$PATH"' >> ~/.bashrc
RUN echo 'eval "$(jenv init -)"' >> ~/.bashrc

Expand All @@ -77,24 +82,24 @@ ARG gcloud_install_script=${gcloud_home}/google-cloud-sdk/install.sh
ARG gcloud_bin=${gcloud_home}/google-cloud-sdk/bin
ENV PATH=${gcloud_bin}:${PATH}
RUN if [ "$gcloud" = true ] ; \
then \
then \
echo "Installing GCloud SDK"; \
apt-get update && apt-get install --no-install-recommends -y \
gcc \
python3 \
python3-dev \
python3-setuptools \
python3-pip && \
gcc \
python3 \
python3-dev \
python3-setuptools \
python3-pip && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
mkdir -p ${gcloud_home} && \
wget --quiet --output-document=/tmp/gcloud-sdk.tar.gz ${gcloud_url} && \
tar -C ${gcloud_home} -xvf /tmp/gcloud-sdk.tar.gz && \
${gcloud_install_script} && \
pip3 uninstall crcmod && \
pip3 install --no-cache-dir -U crcmod; \
else \
else \
echo "Skipping GCloud SDK installation"; \
fi
fi

## Install Android SDK
ARG sdk_version=commandlinetools-linux-6200805_latest.zip
Expand All @@ -117,15 +122,15 @@ RUN mkdir ~/.android && echo '### User Sources for Android SDK Manager' > ~/.and

RUN yes | sdkmanager --sdk_root=$ANDROID_HOME --licenses
RUN sdkmanager --sdk_root=$ANDROID_HOME --install \
"platform-tools" \
"build-tools;${android_build_tools}" \
"platforms;${android_api}"
"platform-tools" \
"build-tools;${android_build_tools}" \
"platforms;${android_api}"
RUN if [ "$android_ndk" = true ] ; \
then \
then \
echo "Installing Android NDK ($ndk_version, cmake: $cmake)"; \
sdkmanager --sdk_root="$ANDROID_HOME" --install \
"ndk;${ndk_version}" \
"cmake;${cmake}" ; \
else \
else \
echo "Skipping NDK installation"; \
fi
fi
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ The image is providing standard tools to build and test Android application:
## Fastlane first-class support
Images are built to have first class support for Fastlane.
Ruby versions in [`normal maintenance`](https://www.ruby-lang.org/en/downloads/branches/) mode are installed using [rbenv](https://github.com/rbenv/rbenv).
If you are using a Fastlane plugin which requires a native library:
If you are using a Fastlane plugin which requires a native library:
- Install it using `apt-get update && apt-get -y install <lib>` in your
CI workflow.
- Comment https://github.com/faberNovel/docker-android/issues/78 so that we can
keep track of missing native libraries and add them to the next image version.

## JDK support
Images support multiple JDK, using [Jenv](https://www.jenv.be/).
The default JDK is JDK 17, but JDK 11 and 8 are also supported (i.e. use `jenv global 1.8` to set JDK to verion 8).
To choose a JDK, make sure the script executes on a bash shell, then use Jenv to set the desired version:
The default JDK is JDK 21, but JDK 17, 11 and 8 are also supported (i.e. use `jenv global 1.8` to set JDK to verion 8).
To choose a JDK, make sure the script executes on a bash shell, then use Jenv to set the desired version:
```
jobs:
my_android_job:
Expand Down
48 changes: 36 additions & 12 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ usage() {
exit 1
}

# Default and parse arguments
android_ndk=false
gcloud=false
check_base_tools=false
large_test=false
android_api=""
android_build_tools=""

while true; do
case "$1" in
--android-ndk ) android_ndk=true; shift ;;
Expand All @@ -30,23 +38,31 @@ while true; do
esac
done

if [ -z "$android_api" ]; then
usage
fi

if [ -z "$android_build_tools" ]; then
# Validate required arguments
if [ -z "$android_api" ] || [ -z "$android_build_tools" ]; then
usage
fi

# Base tools check with comprehensive version reporting
if [ "$check_base_tools" = true ]; then
echo "Java Versions:"
java -version
javac -version
echo "Full Java Version Details:"
java --version

echo "Ruby Version:"
ruby -v
rbenv -v
# if HOME is changed, rbenv should still have access to the install plugin
echo "Checking rbenv plugin installation:"
(
# Changing HOME environment variable in this subshell
export HOME="/tmp"
rbenv install --skip-existing 2.7.1
)

echo "SSH Version:"
ssh -V
fi

Expand All @@ -56,15 +72,16 @@ if [ "$gcloud" = true ]; then
fi

# Setup test app environment variables
export KOTLIN_VERSION="1.9.10"
export GRADLE_VERSION="8.3"
export ANDROID_GRADLE_TOOLS_VERSION="8.1.1"
export KOTLIN_VERSION="1.9.20"
export GRADLE_VERSION="8.5"
export ANDROID_GRADLE_TOOLS_VERSION="8.2.0"
export COMPILE_SDK_VERSION="$android_api"
export BUILD_TOOLS_VERSION="$android_build_tools"
export MIN_SDK_VERSION=21
export TARGET_SDK_VERSION="$android_api"
export NDK_VERSION="21.0.6113669"
export NDK_VERSION="26.1.10909125"

# Function to setup gradle version in wrapper properties
setup_gradle_version() {
if grep -q "distributionUrl" ./gradle/wrapper/gradle-wrapper.properties; then
file="./gradle/wrapper/gradle-wrapper.properties"
Expand All @@ -74,20 +91,25 @@ setup_gradle_version() {
echo "distributionUrl=https\://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip" >> ./gradle/wrapper/gradle-wrapper.properties
}

# Function to execute test
exec_test() {
cd "$1"

setup_gradle_version

gem install bundler:2.3.7
bundle install
bundle exec fastlane android build
}

# Prepare environment
ruby -v
eval "$(jenv init -)"

jenv global 17
# Use Java 21 as default
jenv global 21

# Run tests based on NDK flag
if [ "$android_ndk" = true ]; then
echo "Running tests with ndk"
exec_test "$script_path"/test-app-ndk
Expand All @@ -96,6 +118,7 @@ else
exec_test "$script_path"/test-app
fi

# Run large tests if requested
if [ "$large_test" = true ]; then
echo "Run android tests on Firebase Test Lab"
cd "$script_path"/test-firebase-test-lab
Expand All @@ -105,4 +128,5 @@ if [ "$large_test" = true ]; then
bundle install
bundle exec fastlane android integrated_test
fi

exit 0
21 changes: 10 additions & 11 deletions tests/test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = "21"
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}