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

Document proguard rules #58

Closed
swankjesse opened this Issue May 30, 2014 · 25 comments

Comments

@swankjesse
Copy link
Member

swankjesse commented May 30, 2014

Our users are running into problems with java.nio.file.Path. We have proguard rules that help to work around this. We should document 'em.

See also #42

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Jun 5, 2014

Lint also apparently fails. Sigh.

OkHttp 2.0.0-RC1 - getting this lint error during the build process:

.gradle/caches/[...]/okio-1.0.0.jar:
Invalid package reference in library; not included in Android: java.nio.file.
Referenced from okio.Okio.

via square/okhttp#896

@rockerhieu

This comment has been minimized.

Copy link

rockerhieu commented Jul 2, 2014

Here is how I fixed the Lint error (actually is just a workaround):

  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile('com.squareup.okhttp:okhttp-urlconnection:2.0.0') {
    exclude group: 'com.squareup.okhttp', module: 'okhttp'
  }
  compile('com.squareup.okhttp:okhttp:2.0.0') {
    exclude group: 'com.squareup.okio', module: 'okio'
  }

And with okio-1.0.0.jar inside libs folder, here is the lint configuration:

<lint>
  <issue id="InvalidPackage">
    <ignore path="libs/okio-1.0.0.jar"/>
  </issue>
</lint>
@ollie72

This comment has been minimized.

Copy link

ollie72 commented Jul 23, 2014

I'm using Retrofit with OkHttp and I'm also seeing this. It's a shame as I like to maintain "lint zero". The okhttp exclude in the build.gradle method above gives me this at runtime: "java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.http.RetryableSink" so I tried this in build.gradle

//noinspection InvalidPackage
compile ('com.squareup.okhttp:okhttp-urlconnection:2.0.0')
//noinspection InvalidPackage
compile ('com.squareup.okhttp:okhttp:2.0.0') { exclude group: 'com.squareup.okio', module: 'okio' } 

But that does not stop the lint error. I ended up adding it to lint.xml as a global rule which isn't ideal but does the job.

<issue id="InvalidPackage" severity="ignore" />
@tadfisher

This comment has been minimized.

Copy link

tadfisher commented Aug 2, 2014

If you don't want to ignore InvalidPackage globally, this works as well:

<issue id="InvalidPackage">
    <ignore regexp="okio-1.0.0.jar" />
</issue>
@spengilley

This comment has been minimized.

Copy link

spengilley commented Sep 22, 2014

I too am suffering with this lint failure which adds an ugly red smear to my lint report :)

@crossle

This comment has been minimized.

Copy link

crossle commented Nov 24, 2014

Same problem. +1

@VicV

This comment has been minimized.

Copy link

VicV commented Nov 26, 2014

Just started getting this as of today. Haven't had this problem for months before.

@designatednerd

This comment has been minimized.

Copy link

designatednerd commented Dec 11, 2014

If you're using Gradle, it's definitely a hacky solution, but you can completely disable the linting for invalid packages by adding:

    lintOptions {
        disable 'InvalidPackage'
    }

to your android closure at the app level, and then your app will at least build.

This should definitely get fixed at the okio level, though.

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Dec 11, 2014

Fixed how? There's nothing wrong with it.

@designatednerd

This comment has been minimized.

Copy link

designatednerd commented Dec 11, 2014

Not being able to build without turning off linting for invalid packages means something is wrong. Maybe this is something that needs to get fixed in Gradle and not at your level - is there a way to specify at the repo or pom level that a certain package doesn't need to be checked for on Android?

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Dec 11, 2014

No. You can file a feature request for something like that on http://b.android.com though.

@designatednerd

This comment has been minimized.

Copy link

designatednerd commented Dec 11, 2014

I will - is there any way to add documentation here or at the Retrofit level for this workaround on android since it is a known issue?

@VicV

This comment has been minimized.

Copy link

VicV commented Dec 11, 2014

See, the problem I have is that even with proguard and linting rules, this problem still occurs in this situation:

Project A is main project in Android Studio

Module B is a module I have (a library) that for testing, is imported locally via this way in A's settings.gradle: project(':foo').projectDir = new File(settingsDir,'/path/to/module')

Then project A has this dependency: complile project(:foo)


If module B has okio dependencies, and I run a ./gradlew clean build from project A, as of 0.8.6 the errors will prevent the entire project from being build correctly. This was entirely untrue in the past (as my previous comment mentioned).

However I think this is an issue with the new proguard implementation of AS, given that proguard simply isn't ran on module B during this build step regardless of the settings.

So, in developing a library dependent on okio, its quite frustrating. But, it all works fine I suppose, I just have to build from the 'correct' locations now.

Merely an inconvenience, and nothing to 'fix'.

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Dec 11, 2014

At the very least this case should probably be a lint warning, not an error. Perhaps they're not interested in that granular of parsing for what is happening here.

In Okio's case, it's impossible to link against these methods in your code therefore it's impossible to cause harm to your application (unless you are using reflection and trying to invoke it).

@designatednerd

This comment has been minimized.

Copy link

designatednerd commented Dec 12, 2014

I certainly agree that I would expect this to be a warning, not an error. But for right now, this is getting recognized by gradlew lint as an error.

It would be helpful to have a documented workaround if this is an issue out of control of the okio/Square team.

@monxalo

This comment has been minimized.

Copy link

monxalo commented Feb 3, 2015

Rather than disabling the lint check you can change its severity.

lintOptions {
   warning 'InvalidPackage'
}

This way it will still show up in lint results with a warning.

@swankjesse swankjesse added this to the 1.3 milestone Feb 24, 2015

stefanhoth added a commit to gdg-x/frisbee that referenced this issue Mar 3, 2015

stefanhoth added a commit to gdg-x/frisbee that referenced this issue Mar 4, 2015

@swankjesse swankjesse modified the milestones: Icebox, 1.3, 1.4 Mar 17, 2015

jaggernod pushed a commit to reark/reark that referenced this issue May 23, 2015

Fix: Release is not building
Lint does complain that Okio is an invalid package

square/okio#58

jaggernod pushed a commit to reark/reark that referenced this issue May 23, 2015

Fix: Release is not building
Lint does complain that Okio is an invalid package

square/okio#58

ksheremet added a commit to dasfoo/rover-android-client that referenced this issue May 10, 2016

blundell pushed a commit to zettaapi/zetta-starter-app-android that referenced this issue Jun 7, 2016

virtualandy added a commit to virtualandy/RxExamples that referenced this issue Jul 1, 2016

Build fails on lint error due to okio dep
`./gradlew build` will fail due to a lint error caused by the inclusion of OkHttp/Okio. The error is something like:
```
Invalid package reference in library; not included in Android: java.nio.file.
Referenced from okio.Okio.
```

[Issue in the Okio repo documenting this](square/okio#58) along with steps to lower the level of the flag to a "warning", which is what I've done here.

Granted, that affects the entire build, not just the one package. [Here's a similar proposed fix for a similar lint error](http://stackoverflow.com/questions/21827004/gradle-dagger-lint-ignore-by-package) via StackOverflow.

This should allow someone to clone/download the repo, run `./gradlew build` and have it succeed. I've tested locally and it seems good.
@Macarse

This comment has been minimized.

Copy link

Macarse commented Jul 14, 2016

<issue id="InvalidPackage" severity="error">
        <ignore regexp="okio.*jar" />
</issue>

to keep it as an error and ignore okio's jar file.

ricalo pushed a commit to microsoftgraph/android-java-snippets-rest-sample that referenced this issue Aug 4, 2016

Ricardo Loo
Added lintOptions entry to switch an error caused by...
... transitive dependency okio

For more information, see square/okio#58

wilsonpage added a commit to wilsonpage/react-native-google-analytics-bridge that referenced this issue Aug 9, 2016

inv3rse added a commit to inv3rse/ProxerTv that referenced this issue Sep 18, 2016

@swankjesse swankjesse modified the milestones: 1.11, 1.10 Oct 12, 2016

SUPERCILEX pushed a commit to SUPERCILEX/Robot-Scouter that referenced this issue Nov 12, 2016

Alex Saveau
@3flex

This comment has been minimized.

Copy link

3flex commented Mar 14, 2017

Closed by #275?

Regarding Android lint, seems #58 (comment) is the best workaround as it disables the error only for this lib. Could this be added to the README?

noamtamim added a commit to kaltura/playkit-android-samples that referenced this issue Mar 19, 2017

@noamtamim

This comment has been minimized.

Copy link

noamtamim commented Mar 19, 2017

Is there a plan to fix the lint part of this issue? You may consider offering a separate build of the library for Android, that doesn't contain the non-Android java.nio.file.Path class.

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Mar 19, 2017

@swankjesse swankjesse removed this from the 1.11 milestone May 1, 2017

@therajanmaurya therajanmaurya referenced this issue May 16, 2017

Merged

style: travis script added #18

3 of 3 tasks complete

Chesire added a commit to Chesire/EorzeanInfo that referenced this issue May 29, 2017

digitaldan added a commit to openhab/openhab-android that referenced this issue Jun 20, 2017

@jaredsburrows

This comment has been minimized.

Copy link

jaredsburrows commented Sep 12, 2017

I tried to do this here: #268.

@swankjesse

This comment has been minimized.

Copy link
Member Author

swankjesse commented May 13, 2018

We have a ProGuard section on our main readme now.

@swankjesse swankjesse closed this May 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.