Skip to content

Commit

Permalink
Upgrade dexmaker to AGP 8.5
Browse files Browse the repository at this point in the history
The intent of this change is to migrate to Android Gradle Plugin 8.5.0,
but as a consequence introduces a few other changes:

* The minimum viable SDK is now 21, as NDK r26 dropped support for 19.
* The minimum Gradle version is now 8, as AGP 8.5.0 requires it.
* The minimum JDK version is now 17, as AGP 8.5.0 requires it.
* The errorprone library was upgraded to provide new JDK classes.
* The publishing scripts were updated to use the new Gradle properties.
* Errorprone fixes were applied to the inline-extended classes.
  • Loading branch information
prashanthswami committed Aug 1, 2024
1 parent d21d6c5 commit 3dd7e8b
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17

- name: Cache Gradle Files
uses: actions/cache@v2
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17

- name: Build
run: ./gradlew build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- uses: gradle/wrapper-validation-action@v1

2 changes: 1 addition & 1 deletion .github/workflows/merge-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17

- name: Cache Gradle Files
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-maven-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17

- name: Build
run: ./gradlew build
Expand Down
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.android.tools.build:gradle:8.5.0'
}
}

Expand All @@ -16,4 +16,23 @@ allprojects {

group = GROUP_ID
version = VERSION_NAME

// The `errorprone` library now needs some additional exports to allow it to
// perform reflections. The flags passed to the JVM are from the errorprone
// documentation: https://errorprone.info/docs/installation.
tasks.withType(JavaCompile) {
options.fork = true
options.forkOptions.jvmArgs += [
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"
]
}
}
3 changes: 2 additions & 1 deletion dexmaker-mockito-inline-dispatcher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.application'

android {
namespace 'com.android.dexmaker.mockito.inline.dispatcher'
compileSdkVersion 32

defaultConfig {
applicationId 'com.android.dexmaker.mockito.inline.dispatcher'
minSdkVersion 28
targetSdkVersion 32
targetSdkVersion 33
versionName VERSION_NAME
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest package="com.android.dexmaker.mockito.inline.dispatcher">
<manifest>
<application />
</manifest>
3 changes: 2 additions & 1 deletion dexmaker-mockito-inline-extended-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'

android {
namespace 'com.android.dexmaker.mockito.inline.extended.tests'
compileSdkVersion 32

android {
Expand All @@ -11,7 +12,7 @@ android {

defaultConfig {
minSdkVersion 28
targetSdkVersion 32
targetSdkVersion 33

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest package="com.android.dexmaker.mockito.inline.extended.tests"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

Expand Down
7 changes: 4 additions & 3 deletions dexmaker-mockito-inline-extended/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ apply from: "$rootDir/gradle/publishing_aar.gradle"
description = 'Extension of the Mockito Inline API to allow mocking static methods on the Android Dalvik VM'

android {
namespace 'com.android.dx.mockito.inline.extended'
compileSdkVersion 32

android {
Expand All @@ -17,8 +18,8 @@ android {
}

defaultConfig {
minSdkVersion 9
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33
}

externalNativeBuild {
Expand All @@ -40,7 +41,7 @@ tasks.withType(JavaCompile) {
}

dependencies {
errorprone "com.google.errorprone:error_prone_core:2.5.1"
errorprone "com.google.errorprone:error_prone_core:2.29.2"
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"

implementation project(':dexmaker-mockito-inline')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.dx.mockito.inline.extended" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public Collection<InvocationHandlerAdapter> values() {
}

@Override
@SuppressWarnings("InfiniteRecursion")
public Set<Entry<Object, InvocationHandlerAdapter>> entrySet() {
Set<Entry<Object, InvocationHandlerAdapter>> set = new HashSet<>(entrySet().size());
for (Entry<MockMarkerKey, InvocationHandlerAdapter> entry : markerToHandler.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private static Class nameToType(String name) throws ClassNotFoundException {
* @param methodParameters Parameter of method
* @return {code true} iff the method would have be handled by superClass
*/
@SuppressWarnings("ReturnValueIgnored")
private static boolean isMethodDefinedBySuperClass(Class<?> subclass, Class<?> superClass,
String methodName,
Class<?>[] methodParameters) {
Expand Down
3 changes: 2 additions & 1 deletion dexmaker-mockito-inline-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'

android {
namespace 'com.android.dexmaker.mockito.inline.tests'
compileSdkVersion 32

android {
Expand All @@ -12,7 +13,7 @@ android {

defaultConfig {
minSdkVersion 28
targetSdkVersion 32
targetSdkVersion 33

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
1 change: 0 additions & 1 deletion dexmaker-mockito-inline-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:tools="http://schemas.android.com/tools"
package="com.android.dexmaker.mockito.inline.tests"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true"
tools:ignore="HardcodedDebugMode" />
Expand Down
7 changes: 4 additions & 3 deletions dexmaker-mockito-inline/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ apply from: "$rootDir/gradle/publishing_aar.gradle"
description = 'Implementation of the Mockito Inline API for use on the Android Dalvik VM'

android {
namespace 'com.android.dx.mockito.inline'
compileSdkVersion 32

android {
Expand All @@ -17,8 +18,8 @@ android {
}

defaultConfig {
minSdkVersion 1
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33
}

externalNativeBuild {
Expand All @@ -35,7 +36,7 @@ tasks.withType(JavaCompile) {
}

dependencies {
errorprone "com.google.errorprone:error_prone_core:2.5.1"
errorprone "com.google.errorprone:error_prone_core:2.29.2"
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"

implementation project(':dexmaker')
Expand Down
2 changes: 1 addition & 1 deletion dexmaker-mockito-inline/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest package="com.android.dx.mockito.inline">
<manifest>
<application />
</manifest>
5 changes: 3 additions & 2 deletions dexmaker-mockito-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'

android {
namespace 'com.android.dexmaker.mockito.tests'
compileSdkVersion 32

android {
Expand All @@ -11,8 +12,8 @@ android {
}

defaultConfig {
minSdkVersion 14
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
1 change: 0 additions & 1 deletion dexmaker-mockito-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:tools="http://schemas.android.com/tools"
package="com.android.dexmaker.mockito.tests"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true"
tools:ignore="HardcodedDebugMode"/>
Expand Down
6 changes: 3 additions & 3 deletions dexmaker-mockito/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description = "Implementation of the Mockito API for use on the Android Dalvik V
apply plugin: 'java-library'
apply from: "$rootDir/gradle/publishing.gradle"

targetCompatibility = '1.7'
sourceCompatibility = '1.7'
java.targetCompatibility = '1.8'
java.sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
options.errorprone {
Expand All @@ -17,7 +17,7 @@ tasks.withType(JavaCompile) {
}

dependencies {
errorprone "com.google.errorprone:error_prone_core:2.5.1"
errorprone "com.google.errorprone:error_prone_core:2.29.2"
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"

implementation project(':dexmaker')
Expand Down
5 changes: 3 additions & 2 deletions dexmaker-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.application'

android {
namespace 'com.linkedin.dexmaker'
compileSdkVersion 32

defaultConfig {
applicationId 'com.linkedin.dexmaker'
minSdkVersion 14
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName VERSION_NAME

Expand Down
5 changes: 2 additions & 3 deletions dexmaker-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest package="com.linkedin.dexmaker"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application android:allowBackup="false" />
</manifest>
</manifest>
6 changes: 3 additions & 3 deletions dexmaker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description = "A utility for doing compile or runtime code generation targeting
apply plugin: 'java'
apply from: "$rootDir/gradle/publishing.gradle"

targetCompatibility = '1.7'
sourceCompatibility = '1.7'
java.targetCompatibility = '1.8'
java.sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
options.errorprone {
Expand All @@ -21,7 +21,7 @@ javadoc {
}

dependencies {
errorprone "com.google.errorprone:error_prone_core:2.5.1"
errorprone "com.google.errorprone:error_prone_core:2.29.2"
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"

implementation 'com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppDataDirGuesser {
// Copied from UserHandle, indicates range of uids allocated for a user.
public static final int PER_USER_RANGE = 100000;

@SuppressWarnings("ReturnValueIgnored")
public File guess() {
try {
ClassLoader classLoader = guessSuitableClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public static void setInvocationHandler(Object instance, InvocationHandler handl
/**
* Returns true if {@code c} is a proxy class created by this builder.
*/
@SuppressWarnings("ReturnValueIgnored")
public static boolean isProxyClass(Class<?> c) {
// TODO: use a marker interface instead?
try {
Expand Down
25 changes: 7 additions & 18 deletions gradle/publishing_aar.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

tasks.register("sourcesJar", Jar) {
classifier 'sources'
from android.sourceSets.main.java.srcDirs
}

tasks.register("javadoc", Javadoc) {
failOnError false
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

tasks.register("javadocJar", Jar) {
dependsOn javadoc
classifier 'javadoc'
from javadoc.destinationDir
android {
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

// AGP creates the components in afterEvaluate, so we need to use it too
Expand All @@ -26,9 +18,6 @@ afterEvaluate {
maven(MavenPublication) {
from components.release

artifact sourcesJar
artifact javadocJar

pom {
name = 'Dexmaker'
description = project.description
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 3dd7e8b

Please sign in to comment.