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

Android Lint Error 1.3.6 - Invalid package reference #2004

Closed
ZakTaccardi opened this issue May 8, 2020 · 8 comments
Closed

Android Lint Error 1.3.6 - Invalid package reference #2004

ZakTaccardi opened this issue May 8, 2020 · 8 comments
Labels

Comments

@ZakTaccardi
Copy link

I'm seeing the following Android lint error when upgrading from 1.3.5 to 1.3.6

Package not included in Android
../../../../../../.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.3.6/84cc2e5a484555e49e908fd831ff503303401dd0/kotlinx-coroutines-core-1.3.6.jar: Invalid package reference in org.jetbrains.kotlinx:kotlinx-coroutines-core; not included in Android: java.lang.instrument. Referenced from kotlinx.coroutines.debug.AgentPremain.
This check scans through libraries looking for calls to APIs that are not included in Android.

When you create Android projects, the classpath is set up such that you can only access classes in the API packages that are included in Android. However, if you add other projects to your libs/ folder, there is no guarantee that those .jar files were built with an Android specific classpath, and in particular, they could be accessing unsupported APIs such as java.applet.

This check scans through library jars and looks for references to API packages that are not included in Android and flags these. This is only an error if your code calls one of the library classes which wind up referencing the unsupported package.
To suppress this error, use the issue id "InvalidPackage" as explained in the Suppressing Warnings and Errors section.
@ZacSweers
Copy link
Contributor

ZacSweers commented May 10, 2020

As a temporary workaround, you can suppress this in lint in your lint XML config

<lint>
    <!-- Temporary until https://github.com/Kotlin/kotlinx.coroutines/issues/2004 is resolved. -->
    <issue id="InvalidPackage">
        <ignore path="**/kotlinx-coroutines-core-*.jar"/>
    </issue>
</lint>

@qwwdfsad
Copy link
Member

This is indeed a very unfortunate problem, we never tested lint check.
Ignoring core artifact should be completely safe, actual code with java.lang.instrument is never loaded (unless core artifact is used as an argument to -javaagent).

Hopefully, I will release a 1.3.7 release with lint suppression next week

@qwwdfsad
Copy link
Member

I've published a fixed version 1.3.6-lint to my bintray and tested it against a bunch of trivial projects.

It would be nice if someone could verify it against their (likely more complex and real-world-ish) projects before we release it as 1.3.7.

@sorinirimies
Copy link

sorinirimies commented May 13, 2020

@qwwdfsad I confirm that the 1.3.6-lint works.
The Builds went through our CI/CD and our Monorepo project works as expected.
We have quite a large codebase that heavily relies on the coroutines core and android lib, and we just refactored our Channels to the new StateFlow.
I couldn't observe any abnormalities.

@mhernand40
Copy link

@qwwdfsad I too can confirm that 1.3.6-lint works for my project. All CI checks passed for us. 🙂 🎉

@ZacSweers
Copy link
Contributor

Same here

ibara1454 added a commit to ibara1454/secure-shared-preferences that referenced this issue May 14, 2020
guhungry added a commit to guhungry/android-photo-manipulator that referenced this issue May 17, 2020
@chrimaeon
Copy link

Works for my projects!

hossain-khan added a commit to hossain-khan/android-police-brutality-incidents that referenced this issue Jun 22, 2020
https://github.com/amardeshbd/android-police-brutality-incidents/pull/146/checks?check_run_id=793953609
```
  Errors found:

  /home/runner/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.3.6/84cc2e5a484555e49e908fd831ff503303401dd0/kotlinx-coroutines-core-1.3.6.jar: Error: Invalid package reference in org.jetbrains.kotlinx:kotlinx-coroutines-core; not included in Android: java.lang.instrument. Referenced from kotlinx.coroutines.debug.AgentPremain. [InvalidPackage]
```

See
* Kotlin/kotlinx.coroutines#2004
* coil-kt/coil#430
recheej pushed a commit to recheej/kotlinx.coroutines that referenced this issue Dec 28, 2020
gnarea added a commit to relaycorp/relaynet-gateway-android that referenced this issue Feb 23, 2021
@jolaf
Copy link

jolaf commented May 9, 2022

I'm seeing exactly the same problem on 1.6.1:

../../../../../../.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.6.1-native-mt/ee5d3def1a25e11bb9450ce73c7dd1d8163ec856/kotlinx-coroutines-core-jvm-1.6.1-native-mt.jar: Error: Invalid package reference in org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm; not included in Android: java.lang.instrument. Referenced from kotlinx.coroutines.debug.AgentPremain. [InvalidPackage]

Explanation for issues of type "InvalidPackage":
This check scans through libraries looking for calls to APIs that are not included in Android.
When you create Android projects, the classpath is set up such that you can only access classes in the API packages that are included in Android.
However, if you add other projects to your libs/ folder, there is no guarantee that those .jar files were built with an Android specific classpath, and in particular, they could be accessing unsupported APIs such as java.applet.
This check scans through library jars and looks for references to API packages that are not included in Android and flags these. This is only an error if your code calls one of the library classes which wind up referencing the unsupported package.

Should I reopen the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants