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
Closed

Document proguard rules #58

swankjesse opened this issue May 30, 2014 · 25 comments

Comments

@swankjesse
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link

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
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
Copy link

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
Copy link

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

@crossle
Copy link

crossle commented Nov 24, 2014

Same problem. +1

@VicV
Copy link

VicV commented Nov 26, 2014

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

@designatednerd
Copy link

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
Copy link
Collaborator

Fixed how? There's nothing wrong with it.

@designatednerd
Copy link

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
Copy link
Collaborator

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

@designatednerd
Copy link

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
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
Copy link
Collaborator

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
Copy link

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
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 pushed a commit to gdg-x/frisbee that referenced this issue Mar 3, 2015
stefanhoth pushed 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
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
Lint does complain that Okio is an invalid package

square/okio#58
@Macarse
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.

@3flex
Copy link
Contributor

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
Copy link

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
Copy link
Collaborator

JakeWharton commented Mar 19, 2017 via email

@swankjesse swankjesse removed this from the 1.11 milestone May 1, 2017
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
Copy link
Contributor

I tried to do this here: #268.

@swankjesse
Copy link
Collaborator Author

We have a ProGuard section on our main readme now.

kindweb223 pushed a commit to kindweb223/react-native-goole-analysis that referenced this issue Mar 23, 2019
kindweb223 pushed a commit to kindweb223/react-native-goole-analysis that referenced this issue Apr 18, 2020
mobiledev7 added a commit to mobiledev7/react-native-share that referenced this issue Dec 12, 2022
WictorWilnd pushed a commit to WictorWilnd/react-native-device-info that referenced this issue Feb 27, 2023
wdavis122 added a commit to wdavis122/react-native-device-info that referenced this issue Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests