koush / ion

Android Asynchronous Networking and Image Loading
Other
6.29k stars 1.03k forks source link

Dependency on android.support.v4.app.Fragment? #327

Open commonsguy opened 10 years ago

commonsguy commented 10 years ago

I am attempting to update my Ion sample from my book to the current 1.3.7 from the ancient 1.1.8 that it currently rocks.

However, when I replace the Ion and AndroidAsync JARs in the Eclipse project, I get the following compile error when I try referencing Ion:

The type android.support.v4.app.Fragment cannot be resolved. It is indirectly referenced from required .class files

This project has never used the Android Support package's backport of fragments -- it uses the native API Level 11+ fragments.

I have cleaned the project, restarted Eclipse, sprinkled a pentagram of dried bat blood on the office floor around my development notebook while chanting death metal lyrics backwards -- you know, the usual stuff to fix this sort of problem. Nothing has worked. The same code is happy as a clam with 1.1.8. With 1.3.7, Ion references result in the compile error, both for JSON and for images. Hence, this really feels to me like something with the JARs.

Any ideas?

Thanks!

koush commented 10 years ago

Ion now has support for both native and support fragments, as a context source. It uses them to manage the request lifecycle and cancelling (isDetached, etc).

I'm surprised it is resulting in a compile error, as I'm able to include it in projects, without having to include the support library. I've tested this with both IntelliJ and gradle builds.

I'll see if I can figure out a way to resolve this in eclipse.

commonsguy commented 10 years ago

Note that both standalone Gradle for Android and Android Studio give me the same error, pulling Ion 1.3.7 from Maven Central as opposed to from a local JAR. I have uploaded the project as a ZIP archive in case you need help in reproducing it. I have also tried removing greenrobot's EventBus from the build, with no change.

hernan commented 10 years ago

I just created a new project with a blank activity and just added ion in Gradle in build.gradle file and used an example for test and get the v4.app lib error.

the references to the lib are there, https://github.com/koush/ion/search?q=v4.app

koush commented 10 years ago

Yes, they are there, I'm trying to figure out how to make it an optional dependency. May not be possible though, without changing the API.

In the meantime, I'd suggest adding the support library (or forking ion and removing that call, as it is optional).

ion-v2 will be out soon, and I'll be breaking some APIs in that update. I'll figure out how to fix this in that same release.

koush commented 10 years ago

I may end up creating a couple Ion classes...

com.koushikdutta.ion.Ion com.koushikdutta.ion.support.Ion

This is not ideal though.

koush commented 10 years ago

Another thought is

Ion.with(IFragment fragment)

where IFragment implements everything necessary (by default):

interface IFragment {
  Activity getActivity();
  boolean isDetached();
}

Fragments would need to be tagged with this interface though.

robUx4 commented 10 years ago

Way more inconvenient than 2 packages. At least with 2 packages, when you use support Fragment it will not compile and thus you're forced to do the right thing.

hernan commented 10 years ago

I'm new to Android dev so can't advise about this things, as new comer to me two packages "seems right", is like the sdk deal with appcompat.

AaronChoi commented 10 years ago

so, now don't you have any idea to resolve this problem?

fliiiix commented 9 years ago

Any updates on this?

koush commented 9 years ago

Problem with 2 packages is that Ion.getInstance("whatever").build(fragment) won't work

fbis251 commented 9 years ago

@koush why not do an instanceof check to verify that whether or not an android.app.Fragment object was passed in?

Although I don't think this will help if the call to the support version is kept in the code, it may still cause the compile error.

koush commented 9 years ago

@fbis251

Then it would need to take an untyped Object parameter, which is pretty gross.

commonsguy commented 9 years ago

ion-v2 will be out soon, and I'll be breaking some APIs in that update. I'll figure out how to fix this in that same release.

FWIW, note that this problem still exists in the current v2 edition of Ion.

metinkale38 commented 5 years ago

i know its a 5 years old issue, but its still present in 2.2.1...

I am using Android Jetpack (with androidx.app.Fragment) and am not using the android.support.* Libs.

I have just set up Gitlab-CI for my project... locally i do not have this problem, but the CI Task fails with that error...

Is there a proper solution for that issue?

Edit: i found a solution (which was also the reason, why it worked locally, but not in the CI-Task): simply adding these lines to gradle.properties

android.enableJetifier=true
android.useAndroidX=true

Of course, it will only help, if you use Jetpack Libraries

bio12 commented 5 years ago

@metinkale38: Thank you very much. This solved _myproblem to compile your code. gradle.properties is not part of your repository.