From 7bbcfeeb8cfd4831214515c6680a58b47c4a850d Mon Sep 17 00:00:00 2001 From: Mukilan Thiyagarajan Date: Sun, 26 Nov 2023 15:35:32 +0530 Subject: [PATCH] upgrade to gradle 8 and agp 8 Signed-off-by: Mukilan Thiyagarajan --- etc/shell.nix | 6 +- python/servo/package_commands.py | 2 +- support/android/apk/build.gradle | 61 ++----- support/android/apk/gradle.properties | 22 ++- .../gradle/wrapper/gradle-wrapper.properties | 2 +- support/android/apk/servoapp/build.gradle | 27 +-- .../apk/servoapp/src/main/AndroidManifest.xml | 3 +- support/android/apk/servoview/build.gradle | 170 +++++++----------- .../servoview/src/main/AndroidManifest.xml | 3 +- support/android/apk/settings.gradle | 16 ++ 10 files changed, 137 insertions(+), 175 deletions(-) diff --git a/etc/shell.nix b/etc/shell.nix index eca177e6c723a..0aecd6e3977eb 100644 --- a/etc/shell.nix +++ b/etc/shell.nix @@ -7,7 +7,9 @@ let pinnedNixpkgs = import (builtins.fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/${pinnedSha}.tar.gz"; }) {}; + buildToolsVersion = "33.0.2"; androidComposition = androidenv.composeAndroidPackages { + buildToolsVersions = [ buildToolsVersion ]; includeEmulator = true; platformVersions = [ "30" ]; includeSources = false; @@ -57,7 +59,7 @@ clangStdenv.mkDerivation rec { pinnedNixpkgs.gnumake # android build - openjdk8_headless + openjdk17_headless # android, make this conditional? androidSdk @@ -80,6 +82,8 @@ clangStdenv.mkDerivation rec { # Enable colored cargo and rustc output TERMINFO = "${ncurses.out}/share/terminfo"; + GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${buildToolsVersion}/aapt2"; + # Provide libraries that aren’t linked against but somehow required LD_LIBRARY_PATH = lib.makeLibraryPath [ # Fixes missing library errors diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py index 932accd6ae74c..83ef89014bb1d 100644 --- a/python/servo/package_commands.py +++ b/python/servo/package_commands.py @@ -162,7 +162,7 @@ def package(self, build_type: BuildType, android=None, target=None, flavor=None, else: raise Exception("TODO what should this be?") - flavor_name = "Main" + flavor_name = "Basic" if flavor is not None: flavor_name = flavor.title() diff --git a/support/android/apk/build.gradle b/support/android/apk/build.gradle index 9003ae7f33a67..312c50f8606c2 100644 --- a/support/android/apk/build.gradle +++ b/support/android/apk/build.gradle @@ -1,47 +1,31 @@ -import org.apache.tools.ant.taskdefs.condition.Os - -buildscript { - repositories { - jcenter() - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' - } -} - -allprojects { - repositories { - jcenter() - flatDir { - dirs rootDir.absolutePath + "/../../../target/android/aar" - } - google() - } +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '8.0.1' apply false + id 'com.android.library' version '8.0.1' apply false } // Utility methods -String getTargetDir(boolean debug, String arch) { +ext.getTargetDir = { boolean debug, String arch -> def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath return basePath + '/target/android/' + getSubTargetDir(debug, arch) } -String getRealTargetDir(boolean debug, String arch) { +ext.getNativeTargetDir = { boolean debug, String arch -> def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath return basePath + '/target/' + getSubTargetDir(debug, arch) } -String getSubTargetDir(boolean debug, String arch) { +ext.getSubTargetDir = { boolean debug, String arch -> return getRustTarget(arch) + '/' + (debug ? 'debug' : 'release') } -String getJniLibsPath(boolean debug, String arch) { +ext.getJniLibsPath = { boolean debug, String arch -> return getTargetDir(debug, arch) + '/apk/jniLibs' } -static String getRustTarget(String arch) { +ext.getRustTarget = { String arch -> switch (arch.toLowerCase()) { - case 'arm' : return 'arm-linux-androideabi' + //XXX case 'arm' : return 'arm-linux-androideabi' case 'armv7' : return 'armv7-linux-androideabi' case 'arm64' : return 'aarch64-linux-android' case 'x86' : return 'i686-linux-android' @@ -49,9 +33,9 @@ static String getRustTarget(String arch) { } } -static String getNDKAbi(String arch) { +ext.getNDKAbi = { String arch -> switch (arch.toLowerCase()) { - case 'arm' : return 'armeabi' + //XXX case 'arm' : return 'armeabi' case 'armv7' : return 'armeabi-v7a' case 'arm64' : return 'arm64-v8a' case 'x86' : return 'x86' @@ -59,16 +43,10 @@ static String getNDKAbi(String arch) { } } -String getNdkDir() { +ext.getNdkDir = { -> // Read environment variable used in rust build system - String ndkDir = System.getenv('ANDROID_NDK') - if (ndkDir == null) { - ndkDir = System.getenv('ANDROID_NDK_HOME') - } - if (ndkDir == null) { - ndkDir = System.getenv('ANDROID_NDK_ROOT') - } - if (ndkDir == null) { + String ndkRoot = System.getenv('ANDROID_NDK_ROOT') + if (ndkRoot == null) { // Fallback to ndkDir in local.properties def rootDir = project.rootDir def localProperties = new File(rootDir, "local.properties") @@ -77,14 +55,13 @@ String getNdkDir() { properties.load(instr) } - ndkDir = properties.getProperty('ndk.dir') + ndkRoot = properties.getProperty('ndk.dir') } - def cmd = Os.isFamily(Os.FAMILY_WINDOWS) ? 'ndk-build.cmd' : 'ndk-build' - def ndkbuild = new File(ndkDir + '/' + cmd) - if (!ndkbuild.exists()) { + def ndkDir = new File(ndkRoot) + if (!ndkDir.exists()) { throw new GradleException("Please set a valid NDK_HOME environment variable" + "or ndk.dir path in local.properties file"); } - return ndkbuild.absolutePath + return ndkDir.absolutePath } diff --git a/support/android/apk/gradle.properties b/support/android/apk/gradle.properties index 3e412555ad07b..a03b3548962c4 100644 --- a/support/android/apk/gradle.properties +++ b/support/android/apk/gradle.properties @@ -1 +1,21 @@ -org.gradle.jvmargs=-Xmx1024M +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true diff --git a/support/android/apk/gradle/wrapper/gradle-wrapper.properties b/support/android/apk/gradle/wrapper/gradle-wrapper.properties index 558870dad5837..da1db5f04e889 100644 --- a/support/android/apk/gradle/wrapper/gradle-wrapper.properties +++ b/support/android/apk/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/support/android/apk/servoapp/build.gradle b/support/android/apk/servoapp/build.gradle index 2640a597f90ab..0661680dc7d74 100644 --- a/support/android/apk/servoapp/build.gradle +++ b/support/android/apk/servoapp/build.gradle @@ -1,18 +1,21 @@ -apply plugin: 'com.android.application' +plugins { + id 'com.android.application' +} import java.util.regex.Matcher import java.util.regex.Pattern android { - compileSdkVersion 30 - buildToolsVersion '33.0.2' + compileSdk 33 + + namespace 'org.mozilla.servo' buildDir = rootDir.absolutePath + "/../../../target/android/gradle/servoapp" defaultConfig { applicationId "org.mozilla.servo" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 30 versionCode 1 versionName "1.0.0" } @@ -26,7 +29,7 @@ android { flavorDimensions "default" productFlavors { - main { + basic { } googlevr { } @@ -61,19 +64,6 @@ android { } // Custom build types - armDebug { - initWith(debug) - ndk { - abiFilters getNDKAbi('arm') - } - } - - armRelease { - initWith(release) - ndk { - abiFilters getNDKAbi('arm') - } - } armv7Debug { initWith(debug) ndk { @@ -144,7 +134,6 @@ android { } dependencies { - implementation 'com.android.support.constraint:constraint-layout:1.1.2' if (findProject(':servoview-local')) { implementation project(':servoview-local') } else { diff --git a/support/android/apk/servoapp/src/main/AndroidManifest.xml b/support/android/apk/servoapp/src/main/AndroidManifest.xml index 71db56c53a189..3bedf50ffbf0d 100644 --- a/support/android/apk/servoapp/src/main/AndroidManifest.xml +++ b/support/android/apk/servoapp/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ - + diff --git a/support/android/apk/servoview/build.gradle b/support/android/apk/servoview/build.gradle index a7795c3bb683b..7b7c8aad295f2 100644 --- a/support/android/apk/servoview/build.gradle +++ b/support/android/apk/servoview/build.gradle @@ -1,18 +1,28 @@ -apply plugin: 'com.android.library' +plugins { + id 'com.android.library' +} import groovy.io.FileType import java.util.regex.Matcher import java.util.regex.Pattern android { - compileSdkVersion 30 - buildToolsVersion '33.0.2' + compileSdk 33 + + namespace 'org.mozilla.servoview' buildDir = rootDir.absolutePath + "/../../../target/android/gradle/servoview" + ndkPath = getNdkDir() + externalNativeBuild { + ndkBuild { + path file("../jni/Android.mk") + } + } + defaultConfig { - minSdkVersion 18 - targetSdkVersion 30 + minSdk 18 + targetSdk 30 versionCode 1 versionName "1.0" } @@ -26,7 +36,7 @@ android { flavorDimensions "default" productFlavors { - main { + basic { } googlevr { minSdkVersion 21 @@ -59,52 +69,58 @@ android { } // Custom build types - armDebug { - initWith(debug) - ndk { - abiFilters getNDKAbi('arm') - } - } - armRelease { - initWith(release) - ndk { - abiFilters getNDKAbi('arm') - } - } armv7Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('armv7') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('armv7') + arguments(*getNdkBuildArgs(true, 'armv7')) + } } } armv7Release { initWith(release) - ndk { - abiFilters getNDKAbi('armv7') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('armv7') + arguments(*getNdkBuildArgs(false, 'armv7')) + } } } arm64Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('arm64') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('arm64') + arguments(*getNdkBuildArgs(true, 'arm64')) + } } } arm64Release { initWith(release) - ndk { - abiFilters getNDKAbi('arm64') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('arm64') + arguments(*getNdkBuildArgs(false, 'arm64')) + } } } x86Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('x86') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('x86') + arguments(*getNdkBuildArgs(true, 'x86')) + } } } x86Release { initWith(release) - ndk { - abiFilters getNDKAbi('x86') + externalNativeBuild { + ndkBuild { + abiFilters getNDKAbi('x86') + arguments(*getNdkBuildArgs(false, 'x86')) + } } } } @@ -112,12 +128,6 @@ android { sourceSets { main { } - armDebug { - jniLibs.srcDirs = [getJniLibsPath(true, 'arm')] - } - armRelease { - jniLibs.srcDirs = [getJniLibsPath(false, 'arm')] - } armv7Debug { jniLibs.srcDirs = [getJniLibsPath(true, 'armv7')] } @@ -145,34 +155,6 @@ android { } } - - // Call our custom NDK Build task using flavor parameters - tasks.all { - compileTask -> - Pattern pattern = Pattern.compile(/^compile[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)Ndk/) - Matcher matcher = pattern.matcher(compileTask.name) - if (!matcher.find()) { - return - } - - def taskName = "ndkbuild" + compileTask.name - tasks.create(name: taskName, type: Exec) { - def debug = compileTask.name.contains("Debug") - def arch = matcher.group(1) - commandLine getNdkDir(), - 'APP_BUILD_SCRIPT=../jni/Android.mk', - 'NDK_APPLICATION_MK=../jni/Application.mk', - 'NDK_LIBS_OUT=' + getJniLibsPath(debug, arch), - 'NDK_OUT=' + getTargetDir(debug, arch) + '/apk/obj', - 'NDK_DEBUG=' + (debug ? '1' : '0'), - 'APP_ABI=' + getNDKAbi(arch), - 'SERVO_TARGET_DIR=' + getRealTargetDir(debug, arch) - } - - compileTask.dependsOn taskName - } - - project.afterEvaluate { android.libraryVariants.all { variant -> Pattern pattern = Pattern.compile(/^[\w\d]+([A-Z][\w\d]+)(Debug|Release)/) @@ -205,7 +187,7 @@ dependencies { ] // Iterate all build types and dependencies // For each dependency call the proper implementation command and set the correct dependency path - def list = ['arm', 'armv7', 'arm64', 'x86'] + def list = ['armv7', 'arm64', 'x86'] //TODO: document removal of arm for (arch in list) { for (debug in [true, false]) { String basePath = getTargetDir(debug, arch) + "/build" @@ -220,10 +202,12 @@ dependencies { } } - //googlevrImplementation 'com.google.vr:sdk-base:1.140.0' - //googlevrImplementation(name: 'GVRService', ext: 'aar') - //oculusvrImplementation(name: 'OVRService', ext: 'aar') - implementation 'com.android.support.constraint:constraint-layout:1.1.2' + googlevrImplementation 'com.google.vr:sdk-base:1.140.0' + googlevrImplementation(name: 'GVRService', ext: 'aar') + oculusvrImplementation(name: 'OVRService', ext: 'aar') + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' } // folderFilter can be used to improve search performance @@ -259,41 +243,15 @@ class ServoDependency { public String folderFilter; } -apply plugin: 'maven' -import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact - -uploadArchives { - doFirst { - for ( arch in ["arm", "armv7", "arm64", "x86"] ) { - def target = getTargetDir(false, arch) - def aar = new File(target, "servoview.aar") - if (aar.exists()) { - def art = new DefaultPublishArtifact("servoview-" + arch, "aar", "aar", null, new Date(), aar); - project.artifacts.add('archives', art) - } - } - } - repositories.mavenDeployer { - repository(url: "file://localhost/${buildDir}/maven") - def cmd = "git rev-parse --short HEAD" - def proc = cmd.execute() - def commit = proc.text.trim() - def version = "0.0.1." + new Date().format('yyyyMMdd') + "." + commit - for ( arch_ in ["arm", "armv7", "arm64", "x86"] ) { - def arch = arch_ - addFilter(arch) {artifact, file -> artifact.name == "servoview-" + arch} - pom(arch).artifactId = "servoview-" + arch - pom(arch).groupId = 'org.mozilla.servoview' - pom(arch).version = version - pom(arch).project { - licenses { - license { - name 'The Mozilla Public License, v. 2.0' - url 'https://mozilla.org/MPL/2.0/' - distribution 'repo' - } - } - } - } - } +// Call our custom NDK Build task using flavor parameters +def getNdkBuildArgs(boolean debug, String arch) { + return [ + 'APP_BUILD_SCRIPT=../jni/Android.mk', + 'NDK_APPLICATION_MK=../jni/Application.mk', + 'NDK_LIBS_OUT=' + getJniLibsPath(debug, arch), + 'NDK_OUT=' + getTargetDir(debug, arch) + '/apk/obj', + 'NDK_DEBUG=' + (debug ? '1' : '0'), + 'APP_ABI=' + getNDKAbi(arch), + 'SERVO_TARGET_DIR=' + getNativeTargetDir(debug, arch) + ] } diff --git a/support/android/apk/servoview/src/main/AndroidManifest.xml b/support/android/apk/servoview/src/main/AndroidManifest.xml index 1e916f18c9720..94cbbcfc396ac 100644 --- a/support/android/apk/servoview/src/main/AndroidManifest.xml +++ b/support/android/apk/servoview/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/support/android/apk/settings.gradle b/support/android/apk/settings.gradle index 3d36551554c65..d8826861853b6 100644 --- a/support/android/apk/settings.gradle +++ b/support/android/apk/settings.gradle @@ -1,3 +1,19 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + include ':servoapp' def userPropertiesFile = new File('user.properties')