Upgrade Android Gradle plugin to 7.4.0 (#9933)

This is the latest version of the plugin supported by the Gradle version
in use at the moment (7.6).

Note that this also upgrades the R8 optimizer to a version (4.0.48) that
now uses "full mode" optimization by default.

This also splits off Android projects to run under Java 11 (Gradle
plugin requirement) while the other projects continue to run under Java
8.
This commit is contained in:
Terry Wilson 2023-03-08 11:18:27 -08:00 committed by GitHub
parent 2351e37dd7
commit b5b7cacba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 55 additions and 37 deletions

View File

@ -65,6 +65,6 @@ jobs:
- name: Coveralls - name: Coveralls
if: matrix.jre == 8 # Upload once, instead of for each job in the matrix if: matrix.jre == 8 # Upload once, instead of for each job in the matrix
run: ./gradlew :grpc-all:coveralls -x compileJava run: ./gradlew :grpc-all:coveralls -PskipAndroid=true -x compileJava
- name: Codecov - name: Codecov
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v3

View File

@ -11,6 +11,7 @@ repositories {
} }
android { android {
namespace 'io.grpc.android.integrationtest'
sourceSets { sourceSets {
main { main {
java { java {
@ -29,12 +30,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
applicationId "io.grpc.android.integrationtest" applicationId "io.grpc.android.integrationtest"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@ -48,7 +49,7 @@ android {
} }
} }
lintOptions { lintOptions {
disable 'InvalidPackage', 'HardcodedText', disable 'InvalidPackage', 'HardcodedText', 'UsingOnClickInXml',
'MissingClass' // https://github.com/grpc/grpc-java/issues/8799 'MissingClass' // https://github.com/grpc/grpc-java/issues/8799
} }
} }

View File

@ -21,3 +21,7 @@
# Ignores: can't find referenced method from grpc-testing's compileOnly dependency on Truth # Ignores: can't find referenced method from grpc-testing's compileOnly dependency on Truth
-dontwarn io.grpc.testing.DeadlineSubject -dontwarn io.grpc.testing.DeadlineSubject
-keepclassmembers class io.grpc.testing.integration.Messages$* {
*;
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
package="io.grpc.android.integrationtest.test" >
<instrumentation <instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner" android:name="androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
package="io.grpc.android.integrationtest" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -12,6 +11,7 @@
android:name="androidx.multidex.MultiDexApplication" > android:name="androidx.multidex.MultiDexApplication" >
<activity <activity
android:name=".TesterActivity" android:name=".TesterActivity"
android:exported="true"
android:label="@string/app_name" > android:label="@string/app_name" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -8,15 +8,16 @@ plugins {
description = 'gRPC: Android' description = 'gRPC: Android'
android { android {
namespace 'io.grpc.android'
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
consumerProguardFiles "proguard-rules.txt" consumerProguardFiles "proguard-rules.txt"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
package="io.grpc.android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View File

@ -7,6 +7,7 @@ plugins {
description = 'gRPC BinderChannel' description = 'gRPC BinderChannel'
android { android {
namespace 'io.grpc.binder'
sourceSets { sourceSets {
test { test {
java { java {
@ -23,14 +24,14 @@ android {
} }
} }
} }
compileSdkVersion 30 compileSdkVersion 31
compileOptions { compileOptions {
sourceCompatibility 1.8 sourceCompatibility 1.8
targetCompatibility 1.8 targetCompatibility 1.8
} }
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 30 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
package="io.grpc.binder">
<instrumentation <instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner" android:name="androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
package="io.grpc.binder">
</manifest> </manifest>

View File

@ -1,6 +1,4 @@
plugins { plugins {
id "com.android.application" apply false // Necessary for Android plugin to find its classes
id "com.android.library" apply false
id "com.google.osdetector" apply false id "com.google.osdetector" apply false
id "me.champeau.gradle.japicmp" apply false id "me.champeau.gradle.japicmp" apply false
id "net.ltgt.errorprone" apply false id "net.ltgt.errorprone" apply false

View File

@ -28,6 +28,11 @@ echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"
# Proto deps # Proto deps
buildscripts/make_dependencies.sh buildscripts/make_dependencies.sh
# Build Android with Java 11, this adds it to the PATH
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
# Unset any existing JAVA_HOME env var to stop Gradle from using it
unset JAVA_HOME
GRADLE_FLAGS="-Pandroid.useAndroidX=true" GRADLE_FLAGS="-Pandroid.useAndroidX=true"
./gradlew \ ./gradlew \
@ -70,6 +75,7 @@ cp "$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py" "$SET_GITHUB_S
# Collect APK size and dex count stats for the helloworld example # Collect APK size and dex count stats for the helloworld example
sudo update-java-alternatives --set java-1.8.0-openjdk-amd64
HELLO_WORLD_OUTPUT_DIR="$BASE_DIR/github/grpc-java/examples/android/helloworld/app/build/outputs" HELLO_WORLD_OUTPUT_DIR="$BASE_DIR/github/grpc-java/examples/android/helloworld/app/build/outputs"
@ -87,6 +93,7 @@ new_apk_size="$(stat --printf=%s $HELLO_WORLD_OUTPUT_DIR/apk/release/app-release
# Get the APK size and dex count stats using the pull request base commit # Get the APK size and dex count stats using the pull request base commit
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
cd $BASE_DIR/github/grpc-java cd $BASE_DIR/github/grpc-java
./gradlew clean ./gradlew clean
@ -96,6 +103,7 @@ git checkout HEAD^
cd examples/android/helloworld/ cd examples/android/helloworld/
../../gradlew build ../../gradlew build
sudo update-java-alternatives --set java-1.8.0-openjdk-amd64
read -r ignored old_dex_count < \ read -r ignored old_dex_count < \
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk) <("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk)

View File

@ -16,6 +16,12 @@ trap spongify_logs EXIT
# grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and # grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and
# use --include-build for its grpc-core dependency # use --include-build for its grpc-core dependency
echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3" echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3"
# The sdkmanager needs Java 8, but now we switch to 11 as the Android builds
# require it
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
unset JAVA_HOME
LOCAL_MVN_TEMP=$(mktemp -d) LOCAL_MVN_TEMP=$(mktemp -d)
GRADLE_FLAGS="-Pandroid.useAndroidX=true" GRADLE_FLAGS="-Pandroid.useAndroidX=true"
pushd "$GRPC_JAVA_DIR/android" pushd "$GRPC_JAVA_DIR/android"

View File

@ -13,10 +13,11 @@ repositories {
} }
android { android {
compileSdkVersion 29 namespace 'io.grpc.cronet'
compileSdkVersion 31
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
package="io.grpc.cronet" />

View File

@ -6,12 +6,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
applicationId "io.grpc.clientcacheexample" applicationId "io.grpc.clientcacheexample"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
multiDexEnabled true multiDexEnabled true
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"

View File

@ -11,7 +11,8 @@
android:theme="@style/Base.V7.Theme.AppCompat.Light" > android:theme="@style/Base.V7.Theme.AppCompat.Light" >
<activity <activity
android:name="io.grpc.clientcacheexample.ClientCacheExampleActivity" android:name="io.grpc.clientcacheexample.ClientCacheExampleActivity"
android:label="@string/app_name" > android:label="@string/app_name"
android:exported="true" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />

View File

@ -6,12 +6,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
applicationId "io.grpc.helloworldexample" applicationId "io.grpc.helloworldexample"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }

View File

@ -6,12 +6,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
applicationId "io.grpc.routeguideexample" applicationId "io.grpc.routeguideexample"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }

View File

@ -10,7 +10,8 @@
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".RouteGuideActivity" android:name=".RouteGuideActivity"
android:label="@string/app_name" > android:label="@string/app_name"
android:exported="true" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />

View File

@ -6,13 +6,13 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
compileSdkVersion 29 compileSdkVersion 31
defaultConfig { defaultConfig {
applicationId "io.grpc.strictmodehelloworldexample" applicationId "io.grpc.strictmodehelloworldexample"
// API level 28 is required for StrictMode penaltyListener // API level 28 is required for StrictMode penaltyListener
minSdkVersion 28 minSdkVersion 28
targetSdkVersion 29 targetSdkVersion 31
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }

View File

@ -11,7 +11,8 @@
android:theme="@style/Base.V7.Theme.AppCompat.Light" > android:theme="@style/Base.V7.Theme.AppCompat.Light" >
<activity <activity
android:name=".StrictModeHelloworldActivity" android:name=".StrictModeHelloworldActivity"
android:label="@string/app_name" > android:label="@string/app_name"
android:exported="true" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />

View File

@ -1,7 +1,7 @@
pluginManagement { pluginManagement {
plugins { plugins {
id "com.android.application" version "4.2.0" id "com.android.application" version "7.4.0"
id "com.android.library" version "4.2.0" id "com.android.library" version "7.4.0"
id "com.github.johnrengelman.shadow" version "7.1.2" id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.kt3k.coveralls" version "2.12.0" id "com.github.kt3k.coveralls" version "2.12.0"
id "com.google.cloud.tools.jib" version "3.3.1" id "com.google.cloud.tools.jib" version "3.3.1"