j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

Duplicate classes and files when depending on a project using ormlite-core #141

Open aberaud opened 2 years ago

aberaud commented 2 years ago

Our Android project uses ormlite-android and depends on another project that uses ormlite-core.

The base dependency includes ormlite with: implementation ("com.j256.ormlite:ormlite-core:6.1")

And the Android project includes ormlite with: implementation ("com.j256.ormlite:ormlite-android:6.1")

When building the Android project, we get the following errors:

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.j256.ormlite.dao.BaseDaoImpl found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$1 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$2 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$3 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$4 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$5 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseDaoImpl$6 found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.BaseForeignCollection found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableIterable found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableIterator found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableSpliterator found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableSpliteratorImpl found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableWrappedIterable found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
     Duplicate class com.j256.ormlite.dao.CloseableWrappedIterableImpl found in modules ormlite-android-6.1 (com.j256.ormlite:ormlite-android:6.1) and ormlite-core-6.1 (com.j256.ormlite:ormlite-core:6.1)
(...)
com.android.builder.merge.DuplicateRelativeFileException: 2 files found with path 'com/j256/ormlite/core/LICENSE.txt'.

This was working fine with Ormlite 5.x

j256 commented 2 years ago

See the ChangeLog: https://raw.githubusercontent.com/j256/ormlite-core/master/src/main/javadoc/doc-files/changelog.txt

In 6.0 we migrated all of the core classes into the JDBC and Android versions:

* JDBC: ormlite-jdbc jar now includes the -core classes.  No need to import ormlite-core jar anymore.
* ANDROID: ormlite-android jar now includes the -core classes.  No need to import ormlite-core jar anymore.
aberaud commented 2 years ago

Thanks for the reply, however the dependency is not an Android dependency but a pure Java/kotlin dependency, so it can't/shouldn't use the Android package.

What to do in that case ? Thanks.

aberaud commented 2 years ago

@j256 Any idea? This issue prevents us from migrating to ORMLite 6.x

Why not declaring a dependency from ormlite-android to ormlite-core, instead of including all ormlite-core classes in ormlite-android, which seems odd?

j256 commented 2 years ago

Frankly I didn't foresee this issue. I never thought that someone would ever want to depend on both of them. Not everyone uses maven or gradle or some other dependency management system that would automatically pull in jars so it was an attempt to make it easier for folks.

Maybe I should consider rolling that back even though it is going to be painful.

HosseinKurd commented 1 year ago

How to solve it?

jamalnay commented 7 months ago

You just have to exclude the duplicated libraries in gradle like so:

implementation('org.osmdroid:osmdroid-geopackage:6.1.x') {
        exclude group: 'org.osmdroid.gpkg'
        exclude module: 'ormlite-core'
        exclude group: 'com.j256.ormlite'
    }