Skip to content

Commit d654707

Browse files
authored
buildscripts: Build Android with main build in linux_artifacts
Note that this changes the JDK used to compile releases to Java 11. That should only impact the appearance of the Javadoc. This adds the Android SDK to the build container, removing the dependency on the Android SDK being available on the CI host. This allows running on newer Kokoro images. 'Android' and 'Android interop' CIs still depend on the Android SDK being available on the host, but since they aren't used as part of the release process, they can more easily migrate off Kokoro as part of future work. This also causes Android components to now be built with -Werror, as we use -PfailOnWarnings=true in unix.sh but were missing it from the Android build invocations. Gradle will auto-download the necessary version of build-tools. We don't want to download it ourselves because the version we specify might not even be used. Looking at logs, we were previously downloading a version that was unused. We now fork javac to avoid OOM. The build fails 2/3 times before the forking, and 0/3 after.
1 parent b232723 commit d654707

File tree

8 files changed

+24
-44
lines changed

8 files changed

+24
-44
lines changed

android-interop-testing/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ import net.ltgt.gradle.errorprone.CheckSeverity
112112

113113
tasks.withType(JavaCompile).configureEach {
114114
options.compilerArgs += [
115-
"-Xlint:-cast"
115+
"-Xlint:-cast",
116+
"-Xlint:-deprecation", // https://github.com/grpc/grpc-java/issues/10298
116117
]
117118
appendToProperty(it.options.errorprone.excludedPaths, ".*/R.java", "|")
118119
appendToProperty(

binder/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ tasks.withType(JavaCompile).configureEach {
7575
options.compilerArgs += [
7676
"-Xlint:-cast"
7777
]
78+
options.compilerArgs -= ["-Werror"] // https://github.com/grpc/grpc-java/issues/10297
7879
appendToProperty(it.options.errorprone.excludedPaths, ".*/R.java", "|")
7980
}
8081

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ subprojects {
3737
"-Xlint:-try"
3838
]
3939
it.options.encoding = "UTF-8"
40+
// Avoid Gradle OOM.
41+
// https://docs.gradle.org/current/userguide/performance.html#run_the_compiler_as_a_separate_process
42+
it.options.fork = true
4043
if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
4144
it.options.compilerArgs += ["-Werror"]
4245
}

buildscripts/grpc-java-artifacts/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ RUN yum install -y \
77
gcc-c++.i686 \
88
glibc-devel \
99
glibc-devel.i686 \
10-
java-1.8.0-openjdk-devel \
10+
java-11-openjdk-devel \
1111
libstdc++-devel \
1212
libstdc++-devel.i686 \
1313
libstdc++-static \
1414
libstdc++-static.i686 \
1515
libtool \
1616
make \
1717
tar \
18+
unzip \
1819
which \
1920
&& \
2021
yum clean all
2122

23+
ENV ANDROID_HOME=/opt/Android/Sdk
24+
RUN mkdir -p "$ANDROID_HOME/cmdline-tools" && \
25+
curl -Ls -o cmdline.zip \
26+
"https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip" && \
27+
unzip -qd "$ANDROID_HOME/cmdline-tools" cmdline.zip && \
28+
rm cmdline.zip && \
29+
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest" && \
30+
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses
31+
2232
# Install Maven
2333
RUN curl -Ls https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz | \
2434
tar xz -C /var/local

buildscripts/kokoro/android-interop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export CXXFLAGS=-I/tmp/protobuf/include
1616
export LD_LIBRARY_PATH=/tmp/protobuf/lib
1717
export OS_NAME=$(uname)
1818

19-
echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"
19+
(yes || true) | "${ANDROID_HOME}/tools/bin/sdkmanager" --licenses
2020

2121
# Proto deps
2222
buildscripts/make_dependencies.sh

buildscripts/kokoro/android.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cat <<EOF >> gradle.properties
2323
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m
2424
EOF
2525

26-
echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"
26+
(yes || true) | "${ANDROID_HOME}/tools/bin/sdkmanager" --licenses
2727

2828
# Proto deps
2929
buildscripts/make_dependencies.sh

buildscripts/kokoro/linux_artifacts.sh

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,6 @@ trap spongify_logs EXIT
1313
"$GRPC_JAVA_DIR"/buildscripts/build_docker.sh
1414
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-x86 /grpc-java/buildscripts/build_artifacts_in_docker.sh
1515

16-
# grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and
17-
# use --include-build for its grpc-core dependency
18-
echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"
19-
20-
# The sdkmanager needs Java 8, but now we switch to 11 as the Android builds
21-
# require it
22-
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
23-
unset JAVA_HOME
24-
25-
LOCAL_MVN_TEMP=$(mktemp -d)
26-
GRADLE_FLAGS="-Pandroid.useAndroidX=true"
27-
pushd "$GRPC_JAVA_DIR/android"
28-
../gradlew publish \
29-
-Dorg.gradle.parallel=false \
30-
-PskipCodegen=true \
31-
-PrepositoryDir="$LOCAL_MVN_TEMP" \
32-
$GRADLE_FLAGS
33-
popd
34-
35-
pushd "$GRPC_JAVA_DIR/cronet"
36-
../gradlew publish \
37-
-Dorg.gradle.parallel=false \
38-
-PskipCodegen=true \
39-
-PrepositoryDir="$LOCAL_MVN_TEMP" \
40-
$GRADLE_FLAGS
41-
popd
42-
43-
pushd "$GRPC_JAVA_DIR/binder"
44-
../gradlew publish \
45-
-Dorg.gradle.parallel=false \
46-
-PskipCodegen=true \
47-
-PrepositoryDir="$LOCAL_MVN_TEMP" \
48-
$GRADLE_FLAGS
49-
popd
50-
51-
readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}"
52-
mkdir -p "$MVN_ARTIFACT_DIR"
53-
cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/
54-
5516
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-multiarch env \
5617
SKIP_TESTS=true ARCH=aarch_64 /grpc-java/buildscripts/kokoro/unix.sh
5718
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-multiarch env \

buildscripts/kokoro/unix.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ GRADLE_FLAGS+=" -PtargetArch=$ARCH"
4747
GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false"
4848
GRADLE_FLAGS+=" -PfailOnWarnings=true"
4949
GRADLE_FLAGS+=" -PerrorProne=true"
50-
GRADLE_FLAGS+=" -PskipAndroid=true"
5150
GRADLE_FLAGS+=" -Dorg.gradle.parallel=true"
51+
if [[ -z "${ALL_ARTIFACTS:-}" ]]; then
52+
GRADLE_FLAGS+=" -PskipAndroid=true"
53+
else
54+
GRADLE_FLAGS+=" -Pandroid.useAndroidX=true"
55+
fi
5256
export GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
5357

5458
# Make protobuf discoverable by :grpc-compiler

0 commit comments

Comments
 (0)