Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle exclude classes from aar

Im using lib Gson in my dependecies and im import a .aar with some classes from Gson that are imported to a project. When i build my project i keep getting duplicated classes, bcz its on my dependency and aar classes.

How i can exclude gson classes from aar?

I have been trying with:

  • exclude group: I think this is not work since is not a dependency from aar, but classes inside.
  • transitive true, same reason as before

Can i do it? or should i get other .aar with gson as dependecy?

like image 518
user1866731 Avatar asked May 12 '26 15:05

user1866731


1 Answers

  1. Download & Unzip the original .aar library file
  2. Remove the specific class file you want to exclude from the library
unzip original_lib.aar -d out/
cd out/
zip -d classes.jar "com/something/ClassToBeRemoved.class"
jar cvf ../my_new_lib.aar

Now you have a new AAR library file named my_new_lib.aar, which excludes the specified class file.

You can include local .aar library in Gradle using:

implementation files('aar/my_new_lib.aar')

Remember to replace "com/something/ClassToBeRemoved.class" with the actual path and name of the class file you want to exclude. Also, ensure that you are in the correct directory when executing these commands.

This approach allows you to manually remove specific class files from an AAR library.

like image 73
vladaman Avatar answered May 14 '26 05:05

vladaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!