Wish Android App bundle - BundleTool

moster67

Expert
Licensed User
Longtime User
Just wanted to know if it would be possible to add support for Googles App Bundle.
In my case, I have a wrapper which includes native libraries. Recently, the native libraries must also include support for 64bit and depending on the native library I have compiled, the apk size can increase dramatically. If one adds also support for all cpu-architectures, the size increases even further.

The solution seems to be Android's App Bundle. Here is a video about this new feature:


Here is more information:
https://developer.android.com/platform/technology/app-bundle/

It seems like it can be done without using Android Studio and Gradle, using Google's BundleTool:
https://developer.android.com/studio/build/building-cmdline#bundletool-build

However, if you don't want to use Android Studio or Gradle tasks to build bundles—for example, if you use a custom build toolchain—you can use bundletool from the command line to build an app bundle from pre-compiled code and resources. If you haven't already done so, download bundletool from the GitHub repository.
This is why I thought/hoped it could be implemented in B4A too.
 
Last edited:

Microinvest

Member
Licensed User
Longtime User
Recently, while uploading in Google play we started to get this type of warnings, as in B4A we generate APK, not AAB (Google bundle):

"Unoptimised APK

Warning:

This APK results in unused code and resources being sent to users. Your app could be smaller if you used the Android App Bundle. By not optimising your app for device configurations, your app is larger to download and install on users' devices than it needs to be. Larger apps see lower installation success rates and take up storage on users' devices.

We would like to see bundle support as well."
 
Last edited:

Toky Olivier

Active Member
Licensed User
Longtime User
I wanted also to understand more about this Android App Bundle. I'm sure that Erel will find the best method to integrate it in B4A but just to begin, I create a very little and temporary tool to generate *.aab files with B4J. This is my first B4J app, be indulgent please :)

It uses Gradle to build apks from B4A projects and also to produce Android App Bundle. It's just a test, if someone can improve it. For now, I tested just one simple project (the included sample) with just "core.jar" as dependency from the B4A Libraries.
2019-07-02 06_56_27-Gradle build for B4A projects v.1.1.png


To use it:
- First, we need Gradle binaries (what I used is the version 4.6: https://downloads.gradle.org/distributions/gradle-4.6-bin.zip). I don't know if it is OK for another versions. This is the first time I played with Gradle too. Extract the file in one folder and then reference it in the B4J app.
- After, fill all fields: gradle version, android.jar location, B4A installation folder, B4a project file.
- Compile the B4A project (in B4A or click the button Compile with B4A, it uses B4ABuilder) to produce all java sources
- Click Compile with Gradle (to produce apks: debug and releases version) - It takes long times sometimes, gradle download all dependencies file (I don't know yet if one can optimize it... ). May be this step is not needed if you want just to produce App Bundle. Apks produced here is like normal Apks (I think, I tested and they work well)
- Click Create App Bundle to produce App Bundle (sorry, I have no time to test it in Play store yet)

This is not a complete tool but just a test and to show, may be it is possible... I did it rapidly, may be, there are many bugs too.
All file produced by this app are in the subfolder "GradleBuild" in the B4A Project Dir. Produced APKs and AAB ar in the folder: ".GradleBuild\build\outputs"

PS: I am a very newbie in b4j and I don't now yet how to use jshell well... Log data in the TextArea are scrambled, I don't know why?? :eek:

See enclosed the B4J source file, the very sample B4A sample project and produced apk and aab file with the tool.

v0.4: Can compile now projects with b4xlibs (eg: X2 Example pack of @Erel). Not yet for Projects with #AdditionalJar directives or AppCompat Project, etc... Many things that I don't understand well yet. To compile X2 Example pack, compile directly in B4A before to execute #CustomBuildAction directive of the Game class. V.04 needs the ArchiverPlusZip library of @Informatix to handle *.b4xlibs
 

Attachments

  • B4AGradleTest.zip
    8.9 KB · Views: 343
  • GradleBuild-release.apk
    121.1 KB · Views: 349
  • GradleBuild.aab.zip
    117.1 KB · Views: 328
  • B4AGradleBuild v0.3.zip
    6.3 KB · Views: 309
  • B4AGradleBuild v0.4.zip
    6.9 KB · Views: 400
Last edited:

moster67

Expert
Licensed User
Longtime User
Looks interesting - many thanks.
Hopefully next weekend I will have some time to test.
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Toky Olivier,
So I've downloaded all your files and I've given your application a quick try try.

I compile the test app in B4A, then I click the Compile with Gradle button and it appeared to be downloading dependencies, etc. It creates the \GradleBuild folder in the B4A projects folder, but it does not create the \GradleBuild\build\outputs\ folder, even though it says >> Success!! See the *.apk file int the folder: C:\Users\Peter\.......

This was just a quick 10 minute test as I have a few other things I must be getting on with, oh yes and my environments are all filled in...
 

Toky Olivier

Active Member
Licensed User
Longtime User
Hello @Peter Simpson ,
Thank you for your test. Have you tried running directly in command line the generated batch files? What are outputs?

>> cd "your GradleBuild folder"
>> build-apks.bat <== To build with gradle apks
>> gradlew.bat bundleRelease <== To generate App Bundle
 

Toky Olivier

Active Member
Licensed User
Longtime User
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User

Toky Olivier

Active Member
Licensed User
Longtime User
Another quick test today shows that using a simple near blank B4A project and your application does indeed create the .aab file, but on a slightly more complicated project it just fails to do so
Try v0.4 to compile projects that use b4xlib (example: @Erel's X2 Example pack). Another step, project with #Additionaljar, etc. directives...
 

Peter Simpson

Expert
Licensed User
Longtime User
Try v0.4 to compile projects that use b4xlib (example: @Erel's X2 Example pack). Another step, project with #Additionaljar, etc. directives...

Same as before, with a basic small app it works perfect, but with a larger app it fails, in my case it fails with the following error.

B4X:
xCLVew\GradleBuild\.gradle\vcsWorkingDirs) has not been cleaned up in 0 days
>> Unknown Error!!! Try to execute this command in command line in the GradleBuild directory: 'build-apks.bat' to look what's wrong
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
The result AAB will not have any advantage of the original APK unless you are using a library with large native resources such as ffmpeg. In that case the installed app will be a few mb smaller.

Yes I know I'm testing this for the developer, I just wanted to help the developer to get it working correctly. I develop bespoke applications for clients and not for the play store, so having .aab files is completely irrelevant to me.
 
Last edited:
Top