Wish Selectively compiling Google Play APIs into B4A application

b4auser1

Well-Known Member
Licensed User
Longtime User
https://developers.google.com/android/guides/setup
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app.

For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:8.4.0'

It would be great to implement Selectively compiling Google Play APIs into B4A to reduce dramatically size of applications, using Google Play services f.e. : AdMob, GoogleMap, Google Play Game Services, Google Analytics and others. And it will requre less time to complile the applications with Google Play services included. see. https://www.b4x.com/android/forum/threads/google-play-services-installation-tips.45843/#post-388191
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that it is quite simple to manually reduce Google Play Services with a tool such as 7zip.

Open the jar file, click on com\google\android\gms

Sort the folders based on their size. Keep the 'internal' and 'common' folders and remove all the other large folders (that are not needed to your app). Don't deal with the smaller folders, their effect on the APK size is minimal.

For examples if you are only interested in Google Maps, delete all the selected folders:

SS-2015-12-20_11.26.59.png


The jar file size will be about 2mb instead of 6mb.
 

rboeck

Well-Known Member
Licensed User
Longtime User
I reduced the size; it compiles ok, but the size of the apk is still the same. I have used the #AdditionalRes Path, and all other things in manifest for google maps apps. My app is working, but my apk filesize is ~ 5,5 mb, so there is no space for the google play lib. Why does my app work? Is it possible, that a customer needs only one app, which brings google play services to the device and the other apps then can use this play services? (google maps etc.)
 

warwound

Expert
Licensed User
Longtime User
Did you remove the unwanted packages from the google play services .jar file that's in your b4a additional libraries folder or the
google play services .jar file that's located in your android sdk 'extras' folder?
 

rboeck

Well-Known Member
Licensed User
Longtime User
First i reduced only the jar file in android sdk path and this had no effect; now reduced in additional libraries folder and my app shrinks form 5372 to 4695 kb, the compilation time - primary the time for: Convert byte code - optimized dex. (2.36s) Packaging files. (1.12s) is sometimes reduced about 10 sec. But the second compile is much faster than the first, so the timing effect is best only for the first compilation, by the later compilations it seems to be 3 secs.
 

b4auser1

Well-Known Member
Licensed User
Longtime User
left just
common
internal
ads


During start error
java.lang.NoClassDefFoundError: com.google.android.gms.ads.internal.client.zze
 
Top