waqaslam
waqaslam

Reputation: 68187

Gradle Build Error - Program type already present

I'm trying to build an android project which has two modules, one is an application and the other is a library. Both modules have gson-2.8.5.jar files included in their respective libs folder. When I deploy the application, it fails during build with the following error message.

Program type already present: com.google.gson.FieldNamingPolicy$6
Message{kind=ERROR, text=Program type already present: com.google.gson.FieldNamingPolicy$6, sources=[Unknown source file], tool name=Optional.of(D8)}

However, I tested my setup by replacing hard provided .jar files dependencies with gradle's (implementation 'com.google.code.gson:gson:2.8.5') and it worked fine. But I have to use jar files in libs folder since I'm going to use Android.mk file to build the entire project later on, therefore can't depend on gradle injected dependency.

I searched about this error but unfortunately didn't find any useful results. Hope someone knows how to fix this.

Upvotes: 3

Views: 1468

Answers (2)

eleven
eleven

Reputation: 6857

Had the same issue with library:

implementation project(':library')
debugImplementation project(':library')
releaseImplementation 'com.library:1.0.0'

With

./gradlew project:assembleRelease

Gives the error.

Solution: implementation project(':library') should be removed.

Upvotes: 0

waqaslam
waqaslam

Reputation: 68187

Got it fixed. Seems like I had to mark transitive property to false for my included module.

Before:

implementation project(path: ':myLib')

After (fix):

implementation project(path: ':myLib', transitive: false)

Upvotes: 2

Related Questions