commons-app / apps-android-commons

The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons
https://commons-app.github.io/
Apache License 2.0
1.03k stars 1.23k forks source link

Fix errors found by ./gradlew lint #5834

Closed nicolas-raoul closed 2 weeks ago

nicolas-raoul commented 1 month ago
app/src/main/java/fr/free/nrw/commons/di/NetworkingModule.java: Error: The lint detector
    timber.lint.WrongTimberUsageDetector
called context.getMainProject() during module analysis.

This does not work correctly when running in AGP (8.5.0).

In particular, there may be false positives or false negatives because
the lint check may be using the minSdkVersion or manifest information
from the library instead of any consuming app module.

Contact the vendor of the lint issue to get it fixed/updated (if
known, listed below), and in the meantime you can try to work around
this by disabling the following issues:

"LogNotTimber","StringFormatInTimber","ThrowableNotAtBeginning","BinaryOperationInTimber","TimberArgCount","TimberArgTypes","TimberTagLength","TimberExceptionLogging"

Issue Vendors:
Identifier: jetified-timber-4.7.1

Call stack: Context$Companion.checkForbidden$default(Context.kt:689)←Context.getMainProject(Context.kt:103)←WrongTimberUsageDetector.visitMethod(WrongTimberUsageDetector.java:80)←Detector.visitMethodCall(Detector.kt:480)←UElementVisitor$DelegatingPsiVisitor.visitMethodCallExpression(UElementVisitor.kt:1092)←UElementVisitor$DelegatingPsiVisitor.visitCallExpression(UElementVisitor.kt:1072)←UCallExpression.accept(UCallExpression.kt:94)←UQualifiedReferenceExpression.accept(UQualifiedReferenceExpression.kt:34)←UQualifiedReferenceExpression.accept(UQualifiedReferenceExpression.kt:33)←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)←UBlockExpression.accept(UBlockExpression.kt:21)←ULambdaExpression.accept(ULambdaExpression.kt:40)←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)←UCallExpression.accept(UCallExpression.kt:98)←UVariableKt.visitContents(UVariable.kt:68)←UVariableKt.access$visitContents(UVariable.kt:1)←ULocalVariable.accept(UVariable.kt:123)←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)←UDeclarationsExpression.accept(UDeclarationsExpression.kt:22)←ImplementationUtilsKt.acceptList(implementationUtils.kt:15) [LintError]
app/src/main/res/layout/activity_edit.xml:37: Error: Corresponding method handler 'public void getRotatedImage(android.view.View)' not found [OnClick]
      android:onClick="getRotatedImage"
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "OnClick":
   The onClick attribute value should be the name of a method in this View's
   context to invoke when the view is clicked. This name must correspond to a
   public method that takes exactly one parameter of type View.

   Must be a string value, using '\;' to escape characters such as '\n' or
   '\uxxxx' for a unicode character.

app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:138: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
            notificationManager?.notify(
            ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:218: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
                    notificationManager?.notify(
                    ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:316: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager?.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:584: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager?.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:608: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager?.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:627: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager?.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:649: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager?.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:673: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager!!.notify(
        ^
app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt:693: Error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException [MissingPermission]
        notificationManager!!.notify(
        ^

   Explanation for issues of type "MissingPermission":
   This check scans through your code and libraries and looks at the APIs
   being used, and checks this against the set of permissions required to
   access those APIs. If the code using those APIs is called at runtime, then
   the program will crash.

   Furthermore, for permissions that are revocable (with targetSdkVersion 23),
   client code must also be prepared to handle the calls throwing an exception
   if the user rejects the request for permission at runtime.

app/src/main/java/fr/free/nrw/commons/quiz/QuizActivity.java:63: Error: Overriding method should call super.onBackPressed [MissingSuperCall]
    public void onBackPressed() {
                ~~~~~~~~~~~~~
app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java:881: Error: Overriding method should call super.onBackPressed [MissingSuperCall]
    public void onBackPressed() {
                ~~~~~~~~~~~~~

   Explanation for issues of type "MissingSuperCall":
   Some methods, such as View#onDetachedFromWindow, require that you also call
   the super implementation as part of your method.

app/build.gradle: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
app/build.gradle: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
app/build.gradle: Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
app/build.gradle: Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

   Explanation for issues of type "DuplicatePlatformClasses":
   There are a number of libraries that duplicate not just functionality of
   the Android platform but using the exact same class names as the ones
   provided in Android -- for example the apache http classes. This can lead
   to unexpected crashes.

   To solve this, you need to either find a newer version of the library which
   no longer has this problem, or to repackage the library (and all of its
   dependencies) using something like the jarjar tool, or finally, rewriting
   the code to use different APIs (for example, for http code, consider using
   HttpUrlConnection or a library like okhttp).

app/src/main/AndroidManifest.xml:189: Error: Class referenced in the manifest, org.acra.sender.SenderService, was not found in the project or the libraries [MissingClass]
      android:name="org.acra.sender.SenderService"
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "MissingClass":
   If a class is referenced in the manifest or in a layout file, it must also
   exist in the project (or in one of the libraries included by the project.
   This check helps uncover typos in registration names, or attempts to rename
   or move classes without updating the XML references properly.

   https://developer.android.com/guide/topics/manifest/manifest-intro.html

[etc]

214 errors, 1440 warnings

To see the full list, run the lint Gradle task.

baijun6 commented 1 month ago

Hello, am I able to work on this issue? It is my first time working on this repo so please let me know if there is something needed that is not covered by the contribution guidelines.

nicolas-raoul commented 1 month ago

@baijun6 It is yours, looking forward to your pull request(s). Feel free to fix either all issues or only some of them, as you wish. 🙂

baijun6 commented 1 month ago

@nicolas-raoul Thank you! I am currently getting the following error when trying to build the prod, beta and running the app. I'm using the latest Android Studio on macOS Sonoma 14.5, SDK 34, and Andriod gradle plugin 8.5 and gradle 8.7. I would be grateful if you could provide any advice as to how to resolve this :)

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptGenerateStubsBetaDebugKotlin'

e: java.lang.IllegalAccessError: superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x929f129) cannot access class com.sun.tools.javac.main.JavaCompiler (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.main to unnamed module @0x929f129

why-lab commented 1 month ago

Hi, I was having the same error.

What helped me is to change SDK version to 17 in Android Studio (File->Setting->Build,Execution,Deployment->Build->Gradle and change GradleJDK to 17 (I have Azul Zulu version).

Next in build.gradle(app:) I changed this from 11 to 17:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }

Hopefully it helps :)

baijun6 commented 1 month ago

That worked! Thank you :)

baijun6 commented 3 weeks ago

I have made a pull request, fixing some of the issues listed in lint :) https://github.com/commons-app/apps-android-commons/pull/5885