java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Break services out into separate modules

Open Hsaylor opened this issue 10 years ago • 19 comments

Adding async consumption options has helped with the Java SDK's consumability on Android, however there's still the problem of it being quite large. Including the Java SDK pushes Android apps dangerously close to the ~65k method limit. In order to allow for better consumption for Android development we should break each service out into separate modules so developers only have to include services they plan on using. This follows the model Google Play Services use, where you can still download the entire SDK if you desire, but you can also download one service without having to download all others.

Hsaylor avatar Apr 28 '16 21:04 Hsaylor

I think okhttp is doing something like this so we should take a look at what they are doing...

germanattanasio avatar Apr 28 '16 21:04 germanattanasio

+1

GrapeBaBa avatar Apr 29 '16 01:04 GrapeBaBa

(ง •̀_•́)ง

germanattanasio avatar Apr 29 '16 02:04 germanattanasio

To support Android users, we could check the Java SDK for compatibility with ProGuard. That way, the unneeded methods can be removed automatically by Proguard, which is very common among Android projects.

See: Shrink Your Code and Resources

max-vogler avatar Jun 07 '16 17:06 max-vogler

@Hsaylor what do you think? can we have this process described in the android-sdk ?

germanattanasio avatar Jun 08 '16 20:06 germanattanasio

While I'm rather inexperienced with ProGuard, it seems like a possible solution. However, I think at the end of the day it's a question of SDK design. I personally think breaking everything out into separate services is still the better option, again referencing that Google Play Services and OkHttp do this as opposed to saying "just use ProGuard". Simply put I suppose my argument comes down to "why remove extra code when you could just not include it in the first place?"

Hsaylor avatar Jun 13 '16 19:06 Hsaylor

Two options: 1.Use maven profile to build several independent jars. 2.Change the project structure to multiple modules maven/gradle project. Thoughts?

GrapeBaBa avatar Jun 14 '16 06:06 GrapeBaBa

I totally agree with @Hsaylor's view on SDK design.

1.Use maven profile to build several independent jars.

There are many StackOverflow posts and even one Sonatype blog post that warn about this. Personally, I'm seeing some problems here when users depend on multiple of these independent jars, which share the same common code (e.g. http.*)

2.Change the project structure to multiple modules maven/gradle project.

I think this would be the only viable option, even though the effort shouldn't be underestimated. Modularity means splitting up the project into:

  • one base module as shared dependency (containing http.*, util.*, service.*)
  • 18 modules
  • one master module, depending on all 19 submodules

max-vogler avatar Jun 14 '16 09:06 max-vogler

We should keep java-sdk as the module that has all the other modules.

Then we can use something like personality-insights-v2, visual-recognition-v2-beta.

@jsstylos ?

germanattanasio avatar Jun 14 '16 13:06 germanattanasio

Another option would be to do modules per service as opposed to per version. (This wouldn't be as optimized for space, but maybe more logical.)

If java-sdk has all of the other modules would there be a separate common module, so that users who just wanted a single service would import the service module which would pull in the common module?

jsstylos avatar Jun 14 '16 14:06 jsstylos

There will be a common project and each module will import that project. The java-sdk module will import all the services.

germanattanasio avatar Jun 14 '16 14:06 germanattanasio

@germanattanasio And each module will be an entire service wrapper as opposed to a version? So I just add a dependency on the nlc module and get all versions? (that would be my preference at least)

doconnor78 avatar Jun 22 '16 02:06 doconnor78

Yeah, I think you we are all on the same page here. Can someone take this task, fork the repo and do a first pass moving the services to different repos? I completely booked until July 14

germanattanasio avatar Jun 22 '16 04:06 germanattanasio

Well, I guess I will have to do it 😒

germanattanasio avatar Aug 19 '16 19:08 germanattanasio

I've got you, @germanattanasio! I had some free time so I wrote an example of breaking things out using the language translation service. Check the modules-for-android branch and tell me what you think

Hsaylor avatar Aug 22 '16 16:08 Hsaylor

I'll take a look at it @Hsaylor. I tried to do it during the weekend but it was more work than what I thought

germanattanasio avatar Aug 22 '16 18:08 germanattanasio

I realized I pushed up the wrong thing >< Although the concept is the same, it might be a bit harder to see what's going on in that project...

Hsaylor avatar Aug 23 '16 21:08 Hsaylor

@germanattanasio I pushed up a much cleaner version to the modules-for-android branch, which includes all services. Examples and Tests are currently broken, as they haven't been updated to reflect the refactor, but the structure should be much more clear.

Hsaylor avatar Aug 26 '16 17:08 Hsaylor

got it. I will take a look at it this weekend

germanattanasio avatar Aug 26 '16 17:08 germanattanasio