Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Add option to preserve service registry #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuchangyuan
Copy link

Add preserveServiceRegistry, serviceRegistryInclude &
serviceRegistryExclude keys.

When preserveServiceRegistry is true, files in META-INF/services
will be merged, filtered and then insert into the final apk.

Any class name that match any regexp in serviceRegistryInclude and
not match any regexp in serviceRegistryExclude will be included.

Add preserveServiceRegistry, serviceRegistryInclude &
serviceRegistryExclude keys.

When preserveServiceRegistry is true, files in META-INF/services
will be merged, filtered and then insert into the final apk.

Any class name that match any regexp in serviceRegistryInclude and
not match any regexp in serviceRegistryExclude will be included.
@appamatto
Copy link
Collaborator

@yuchangyuan can you explain what the use case for this is?

@yuchangyuan
Copy link
Author

Some library(for example, sesame, http://www.openrdf.org/), use java service registry(or service loader) to provide service(which is a part of android api: http://developer.android.com/reference/java/util/ServiceLoader.html), the usage of ServiceLoader depend on some files in META-INF/services. But these files in seperate jars are not merged into final jar, which cause ServiceLoader can not find any service, and make any code depend on these service not work.

@appamatto
Copy link
Collaborator

Thanks! This does seem interesting. Perhaps we could detect when the services directory is present and do the right thing in that case, with a single switch to turn it off. Is there any reason to exclude service definitions if they are present?

@yuchangyuan
Copy link
Author

Yes, there some use case.

For example, the library jar contains 100 service definitions, and the jar is large. but my android app only need few of these, so I tell proguard to only preserve these I need. If there're more service definitions than actual implementation in classpath, and my code use iterator to find all implementations, maybe a class not found exception will rise(I am not sure about this, but sure that some exception will be thrown).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants