jberkel / android-plugin

An sbt plugin for Android development in Scala
https://groups.google.com/forum/#!forum/scala-on-android
Other
476 stars 113 forks source link

Add option to preserve service registry #151

Open yuchangyuan opened 11 years ago

yuchangyuan commented 11 years ago

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 commented 11 years ago

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

yuchangyuan commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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).