Conversation
Gradle 9 removed several deprecated APIs that this plugin relied on.
This commit updates the plugin to use the new APIs and modernizes the
build configuration to support the changes.
1. Core API Changes (Gradle 9 removals)
- Replace `fileMode = 493` with `filePermissions { unix("rwxr-xr-x") }`
The CopySpec.fileMode property was deprecated in Gradle 8 and removed
in Gradle 9. The new filePermissions API provides the same functionality.
- Replace `project.exec {}` with injected `ExecOperations.exec {}`
The Project.exec() method was deprecated in Gradle 7.5 and removed in
Gradle 9. Tasks must now use service injection to obtain ExecOperations.
This requires changing task classes from `open class` to `abstract class`.
2. Build Configuration Updates
These changes are required because the new Gradle 9 APIs (filePermissions,
ExecOperations) are only available in Gradle 8.3+, so we must compile
against a newer Gradle version:
- Gradle wrapper: 7.1.1 → 8.5
Required to compile against the new APIs (filePermissions added in 8.3)
- Kotlin: 1.3.50 → 1.9.22
The old Kotlin Gradle plugin uses APIs removed in Gradle 8.x
- AGP: 4.0.1 → 8.2.0
Required for Gradle 8.5+ compatibility
- Java target: 1.8 → 17
Required by both Gradle 8.5+ and AGP 8.x
- plugin-publish: 0.14.0 → 1.2.1
The old version uses the `pluginBundle {}` DSL which was removed.
Metadata (website, vcsUrl, tags) now goes in `gradlePlugin {}` block.
- Add Guava dependency
Versions.groovy uses Guava collections which were previously provided
transitively by AGP 4.x but are no longer included in AGP 8.x.
- Add `null` branch to `when` expression in CargoBuildTask
Kotlin 1.7+ requires exhaustive `when` for sealed classes with
nullable types.
3. Test Matrix Updates
- Updated supportedVersions to test AGP 8.x with Gradle 8.x
- Updated jdkVersionFor() to use Java 17 for AGP 8.x
Fixes #160
Move all Project access out of @TaskAction methods into task properties
set at configuration time. This enables Gradle's configuration cache by
ensuring tasks don't reference the Project graph during execution.
- Make CargoBuildTask and GenerateToolchainsTask abstract with injected
ExecOperations and FileSystemOperations services
- Add @Input/@internal properties for all values previously read from
CargoExtension and Project at execution time
- Make Ndk, Toolchain, Features, and FeatureSpec implement Serializable
- Warn when cargo.exec closure is set (not compatible with config cache)
`samples/unittest` is still broken on macOS with architecture
mismatches like:
```
com.nishtahir.androidrust.ExampleUnitTest > testViaJNI FAILED
java.lang.NoClassDefFoundError: Could not initialize class com.nishtahir.androidrust.MainActivity
at com.nishtahir.androidrust.ExampleUnitTest.testViaJNI(ExampleUnitTest.java:30)
Caused by:
java.lang.ExceptionInInitializerError: Exception java.lang.UnsatisfiedLinkError: /Users/nalexander/Library/Caches/JNA/temp/jna17483397431938007410.tmp: dlopen(/Users/nalexander/Library/Caches/JNA/temp/jna17483397431938007410.tmp, 0x0001): tried: '/Users/nalexander/Library/Caches/JNA/temp/jna17483397431938007410.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e' or 'arm64e.v1' or 'arm64' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/nalexander/Library/Caches/JNA/temp/jna17483397431938007410.tmp' (no such file), '/Users/nalexander/Library/Caches/JNA/temp/jna17483397431938007410.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e' or 'arm64e.v1' or 'arm64' or 'arm64')) [in thread "SDK 21 Main Thread"]
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2394)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1970)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
at com.sun.jna.Native.<clinit>(Native.java:195)
at com.sun.jna.NativeLibrary.<clinit>(NativeLibrary.java:87)
at com.nishtahir.androidrust.MainActivity.<clinit>(MainActivity.java:28)
at com.nishtahir.androidrust.ExampleUnitTest.testViaJNA(ExampleUnitTest.java:36)
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.