flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.17k stars 26.65k forks source link

How Recompile with -Xlint:deprecation for details. #147414

Open cavator opened 2 weeks ago

cavator commented 2 weeks ago

Steps to reproduce

i only see people posting errors that show up this code, but i never se no one talking how to Recompile with -Xlint, i did not found anything useful on google. so how?

Expected results

.

Actual results

.

Code sample

.

Screenshots or Video

.

Logs

.

Flutter Doctor output

.

bartekpacia commented 2 weeks ago

Good question! I also sometimes wondered how to see what the deprecations actually are, but never bothered to do it. But this issue motivated me to check it :)

Gradle Groovy DSL

Add the following code to android/build.gradle:

subprojects.forEach { project ->
    logger.quiet("Updating settings for project ${project}")
    project.tasks.withType(JavaCompile) {
        options.compilerArgs += ['-Xlint:deprecation']
    }
}

Gradle Kotlin DSL

Add the following code to android/build.gradle.kts:

subprojects.forEach { project ->
    logger.quiet("Updating settings for project ${project}")
    project.tasks.withType<JavaCompile> {
        options.compilerArgs.addAll(listOf("-Xlint:deprecation"))
    }
}

Then run flutter clean (or a subset of it: ./gradlew clean) and flutter build apk --debug (or a subset of it: ./gradlew :app:assembleDebug).

Here are the logs I got when building my app (which depends on firebase_auth: ^4.19.1 and location: ^6.0.1:

Logs ``` $ flutter build apk --debug /Users/bartek/.cache/pub/hosted/pub.dev/firebase_auth-4.19.1/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthUser.java:343: warning: [deprecation] updateEmail(String) in FirebaseUser has been deprecated .updateEmail(newEmail) ^ /Users/bartek/.cache/pub/hosted/pub.dev/firebase_auth-4.19.1/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthPlugin.java:473: warning: [deprecation] fetchSignInMethodsForEmail(String) in FirebaseAuth has been deprecated .fetchSignInMethodsForEmail(email) ^ 2 warnings /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:67: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated private Integer locationAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY; ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:85: warning: [deprecation] PRIORITY_NO_POWER in LocationRequest has been deprecated put(0, LocationRequest.PRIORITY_NO_POWER); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:86: warning: [deprecation] PRIORITY_LOW_POWER in LocationRequest has been deprecated put(1, LocationRequest.PRIORITY_LOW_POWER); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:87: warning: [deprecation] PRIORITY_BALANCED_POWER_ACCURACY in LocationRequest has been deprecated put(2, LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:88: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated put(3, LocationRequest.PRIORITY_HIGH_ACCURACY); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:89: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated put(4, LocationRequest.PRIORITY_HIGH_ACCURACY); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:90: warning: [deprecation] PRIORITY_LOW_POWER in LocationRequest has been deprecated put(5, LocationRequest.PRIORITY_LOW_POWER); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:249: warning: [deprecation] isFromMockProvider() in Location has been deprecated if (location.isFromMockProvider()) { ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:306: warning: [deprecation] create() in LocationRequest has been deprecated mLocationRequest = LocationRequest.create(); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:308: warning: [deprecation] setInterval(long) in LocationRequest has been deprecated mLocationRequest.setInterval(this.updateIntervalMilliseconds); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:309: warning: [deprecation] setFastestInterval(long) in LocationRequest has been deprecated mLocationRequest.setFastestInterval(this.fastestUpdateIntervalMilliseconds); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:310: warning: [deprecation] setPriority(int) in LocationRequest has been deprecated mLocationRequest.setPriority(this.locationAccuracy); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:311: warning: [deprecation] setSmallestDisplacement(float) in LocationRequest has been deprecated mLocationRequest.setSmallestDisplacement(this.distanceFilter); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java:102: warning: [deprecation] Long(long) in Long has been deprecated final Long updateIntervalMilliseconds = new Long((int) call.argument("interval")); ^ /Users/bartek/.cache/pub/hosted/pub.dev/location-6.0.1/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java:104: warning: [deprecation] Float(double) in Float has been deprecated final Float distanceFilter = new Float((double) call.argument("distanceFilter")); ^ 15 warnings Running Gradle task 'assembleDebug'... 15.8s ✓ Built build/app/outputs/flutter-apk/app-debug.apk. ```

Let me know if it helps!