I've already done this before (i.e., manually refactoring the package source code), but I have no clear idea what the consequences will be.
In {my_flutter_path}\android>
, after executing:
./gradlew build --warning-mode=all
Here are some portions of the logs I got:
Build file 'C:\Users\{username}\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_udid-4.0.0\android\build.gradle': line 20
The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 9.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/8.4/userguide/upgrading_version_6.html#jcenter_deprecation
at build_af532li0bifaqgfn3bsf3h1vp$_run_closure1$_closure3.doCall$original(C:\Users\{username}\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_udid-4.0.0\android\build.gradle:20)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
at build_af532li0bifaqgfn3bsf3h1vp$_run_closure1.doCall$original(C:\Users\{username}\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_udid-4.0.0\android\build.gradle:18)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
If I visit the flutter_udid: ^4.0.0 package on the official pub.dev site, I notice that while I'm using the latest version, the package was published 7 months ago.
I already dropped a message to the author of the package, hoping that they will fix it.
I tried to check the:
Build file 'C:\Users\{username}\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_udid-4.0.0\android\build.gradle': line 20
And here's the specific portion of it that causes the deprecated issue.
rootProject.allprojects {
repositories {
google()
jcenter()
}
}
I replaced jcenter()
with mavenCentral()
to resolve the deprecated issue.
However, I am aware that if I execute these commands:
flutter pub cache clean; flutter pub get;
or
flutter pub cache repair
My changes to that source code would be replaced with the source code from the flutter_udid: ^4.0.0 site.
I am using its features specifically for Android:
Future<String?> _getAndroidID() async {
String udid;
try {
udid = await FlutterUdid
.udid; // able to handle persistent ID even after reinstall
} on PlatformException {
udid = 'Failed to get UDID.';
}
return udid;
}
I know that I could replace this package with another one available from the official pub.dev site, but I am hoping to resolve it through a workaround. I came up with this idea because there's no guarantee that the author will fix that deprecated issue.
I need to avoid my changes being removed when packages are reinstalled, particularly if I turn over this project to another developer.
However, here are my questions:
Does anyone here have any idea how to properly deal with this matter? I mean, should I refactor the package source code over and over again?
Also, is there a way to exclude this file or package from flutter pub cache clean; flutter pub get;
or flutter pub cache repair
?
Fork flutter_udid on GitHub.
In your fork, change jcenter()
→ mavenCentral()
.
Reference your fork in pubspec.yaml
:
dependencies:
flutter_udid:
git:
url: paste your forked repo url
ref: master
ref tells Flutter which
branch
to pull.
now your project will now use your modified fork rather than the original package from pub.dev