Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: lint with error #6296

Closed
Brli opened this issue Feb 14, 2023 · 9 comments
Closed

bug: lint with error #6296

Brli opened this issue Feb 14, 2023 · 9 comments
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android

Comments

@Brli
Copy link

Brli commented Feb 14, 2023

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 4.6.3
  @capacitor/core: 4.6.3
  @capacitor/android: 4.6.3
  @capacitor/ios: 4.6.3

Installed Dependencies:

  @capacitor/cli: 4.6.2
  @capacitor/core: 4.6.2
  @capacitor/android: 4.6.2
  @capacitor/ios: 4.6.2

[error] Xcode is not installed
[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

gradle lint returns

> Task :capacitor-android:lintDebug FAILED
Lint found 7 errors, 0 warnings (8 errors filtered by baseline lint-baseline.xml). First failure:

/home/user/.gradle/caches/transforms-3/1e7439d134cc68f2a6b6424032304fec/transformed/fragment-1.4.1/jars/lint.jar: Error: Library lint checks out of date;

The full lint text report is located at:
  /home/user/project/node_modules/@capacitor/android/capacitor/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':capacitor-android:lintDebug'.
>                 Lint found errors in the project; aborting build.

                  Fix the issues identified by lint, or create a baseline to see only new errors:
                  ```
                  android {
                      lint {
                          baseline = file("lint-baseline.xml")
                      }
                  }
                  ```

                  For more details, see https://developer.android.com/studio/write/lint#snapshot

                  Lint found 7 errors, 0 warnings (8 errors filtered by baseline lint-baseline.xml). First failure:

  /home/user/.gradle/caches/transforms-3/1e7439d134cc68f2a6b6424032304fec/transformed/fragment-1.4.1/jars/lint.jar: Error: Library lint checks out of date;

  The full lint text report is located at:
    /home/user/project/node_modules/@capacitor/android/capacitor/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Expected Behavior

pass without error, or, at least, errors in my own project.

Code Reproduction

Other Technical Details

npm --version output:

node --version output:

pod --version output (iOS issues only):

Additional Context

The full lint-results-debug.txt is as follows:

/home/user/project/node_modules/@capacitor/android/capacitor/lint-baseline.xml: Information: 4 errors/warnings were listed in the baseline file (lint-baseline.xml) but not found in the project; perhaps they have been fixed? Another possible explanation is that lint recently stopped analyzing (and including results from) dependent projects by default. You can turn this back on with android.lintOptions.checkDependencies=true. Unmatched issue types: DefaultLocale, SetJavaScriptEnabled, StaticFieldLeak (2) [LintBaseline]
/home/user/project/node_modules/@capacitor/android/capacitor/lint-baseline.xml: Information: 8 errors were filtered out because they are listed in the baseline file, lint-baseline.xml
 [LintBaseline]
/home/user/.gradle/caches/transforms-3/1e7439d134cc68f2a6b6424032304fec/transformed/fragment-1.4.1/jars/lint.jar: Error: Library lint checks out of date;
these checks will be skipped!

Lint found an issue registry (androidx.fragment.lint.FragmentIssueRegistry)
which was compiled against an older version of lint
than this one. This is usually fine, but not in this
case; some basic verification shows that the lint
check jar references (for example) the following API
which is no longer valid in this version of lint:
org.jetbrains.uast.kotlin.KotlinUClass: org.jetbrains.kotlin.psi.KtClassOrObject getKtClass()
(Referenced from androidx/fragment/lint/OnCreateDialogIncorrectCallbackDetector$UastHandler.class)

Therefore, this lint check library is not included
in analysis. This affects the following lint checks:
FragmentTagUsage
FragmentAddMenuProvider
FragmentBackPressedCallback
FragmentLiveDataObserve
UseRequireInsteadOfGet
UseGetLayoutInflater
DialogFragmentCallbacksDetector
UnsafeRepeatOnLifecycleDetector
DetachAndAttachSameFragment

Recompile the checks against the latest version, or if
this is a check bundled with a third-party library, see
if there is a more recent version available.

Version of Lint API this lint check is using is 11.
The Lint API version currently running is 13 (7.3+). [ObsoleteLintCustomCheck]

   Explanation for issues of type "ObsoleteLintCustomCheck":
   Lint can be extended with "custom checks": additional checks implemented by
   developers and libraries to for example enforce specific API usages
   required by a library or a company coding style guideline.

   The Lint APIs are not yet stable, so these checks may either cause a
   performance degradation, or stop working, or provide wrong results.

   This warning flags custom lint checks that are found to be using obsolete
   APIs and will need to be updated to run in the current lint environment.

   It may also flag issues found to be using a newer version of the API,
   meaning that you need to use a newer version of lint (or Android Studio or
   Gradle plugin etc) to work with these checks.

/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java:239: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
        resId = res.getIdentifier(resName, "mipmap", pkgName);
                    ~~~~~~~~~~~~~
/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java:242: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
            resId = res.getIdentifier(resName, "drawable", pkgName);
                        ~~~~~~~~~~~~~
/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java:246: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
            resId = res.getIdentifier(resName, "raw", pkgName);
                        ~~~~~~~~~~~~~
/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java:342: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
        return context.getResources().getIdentifier(resourceName, dir, context.getPackageName());
                                      ~~~~~~~~~~~~~
/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java:25: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
        getApplication().setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
                                                 ~~~~~~~~~~~~~
/home/user/project/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java:26: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
        setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
                                ~~~~~~~~~~~~~

   Explanation for issues of type "DiscouragedApi":
   Discouraged APIs are allowed and are not deprecated, but they may be unfit
   for common use (e.g. due to slow performance or subtle behavior).

7 errors, 0 warnings (8 errors filtered by baseline lint-baseline.xml)
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@Ionitron Ionitron added the needs reply needs reply from the user label Feb 22, 2023
@Ionitron
Copy link
Collaborator

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 💙

@Ionitron Ionitron removed the needs reply needs reply from the user label Mar 10, 2023
@saschpe
Copy link
Contributor

saschpe commented Apr 3, 2023

That's still an issue, even with 4.7.3

@ptmkenny
Copy link

@ejohanson-vi3
Copy link

ejohanson-vi3 commented May 1, 2023

The problem is definitely still there, and it is completely blocking our release now.

It seems to be very simple-- they have deprecated the use of 'getIdentifier' in Android API 33, because it's hard to optimize.
This problem does not occur when you target Android API 32-- you only see it when targeting API 33 or higher.

The 'getIdentifier' method is used in:
@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java
It should be a simple matter to look in this code for references to the 'getIdentifier' function.
The suggested solution is to replace calls of getIdentifier with references to R.xxx.yyy

Our company's mobile app project is completely stuck because our application has a hard dependency on package androidx.camera:camera-camera2:1.2.0, which absolutely requires Android API 33. As soon as we moved from API 32 to 33, we are stuck with this error.

It is very easy to create a reproduceable capacitor project that shows this problem. All you need to do is edit the 'variables.gradle' file in the android project folder and set compoleSdkVersion=33 and targetSdkVersion=33.

I would encourage the capacitor team to please fix this ASAP!

@ejohanson-vi3
Copy link

ejohanson-vi3 commented May 1, 2023

Here are the steps to reproduce this starting from an empty installation of Node.JS:

  1. npm install -g @ionic/cli
  2. ionic start TestProject blank --type=vue
  3. cd ./TestProject
  4. npm add @capacitor/android
  5. ionic build
  6. npx cap add android
  7. cd ./android
  8. Edit the file variables.gradle
  9. Change the value of compileSdkVersion from 32 to 33
  10. ./gradlew build

You will get the error during the build:

Task :capacitor-android:lintDebug FAILED
Lint found 6 errors, 0 warnings (8 errors filtered by baseline lint-baseline.xml). First failure:

TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java:239: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
resId = res.getIdentifier(resName, "mipmap", pkgName);

There is a reference to a "full lint text report", which contains the following:

TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java:239: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
resId = res.getIdentifier(resName, "mipmap", pkgName);
~~~~~~~~~~~~~
TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java:242: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
resId = res.getIdentifier(resName, "drawable", pkgName);
~~~~~~~~~~~~~
TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java:246: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
resId = res.getIdentifier(resName, "raw", pkgName);
~~~~~~~~~~~~~
TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin\util\AssetUtil.java:342: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
return context.getResources().getIdentifier(resourceName, dir, context.getPackageName());
~~~~~~~~~~~~~
TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\BridgeActivity.java:25: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
getApplication().setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
~~~~~~~~~~~~~
TestProject\node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\BridgeActivity.java:26: Error: Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)). [DiscouragedApi]
setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
~~~~~~~~~~~~~

Explanation for issues of type "DiscouragedApi":
Discouraged APIs are allowed and are not deprecated, but they may be unfit
for common use (e.g. due to slow performance or subtle behavior).

6 errors, 0 warnings (8 errors filtered by baseline lint-baseline.xml)

@dallastjames
Copy link
Contributor

@ejohanson-vi3 thanks for the report here. However, Capacitor 4 does not support targeting SDK 33, which is why you're seeing those errors when trying to change that target value. Capacitor 5 makes all the needed changes needed for your application to correctly support targeting SDK 33. In our testing, this error is not present with Capacitor 5, and we have no plans to support targeting SDK 33 with Capacitor 4. You can upgrade to the latest beta using the cap migrate command (details here), or use the same command to migrate once Capacitor 5 reaches GA here soon.

@ejohanson-vi3
Copy link

ejohanson-vi3 commented May 1, 2023

Ok this is a production grade app that is released to the public, so I'd prefer not to use beta tooling. Is there a target release date for Capacitor 5?

If you're desperate to get this working, you can hack it by adding the following line:
<issue id="DiscouragedApi" severity="ignore" />
to the following file in your project:
node_modules/@capacitor/android/capacitor/lint.xml

@ionitron-bot
Copy link

ionitron-bot bot commented May 31, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android
Projects
None yet
Development

No branches or pull requests

7 participants