File size is the same after running npm run build-android-bundle


#1

Hello All,

I am using vanilla javascript to build an app. My app size remains the same even after using instructions found here: https://docs.nativescript.org/best-practices/bundling-with-webpack with npm run build-android-bundle. After checking the build folder, file size remains 33.6 mb. I was expecting it to be cut in half. Any clue what can be done?


#2

Most of the application size in Android is contributed to by the NativeScript Android runtime (a constant 11mb? in your APK), and then there are several more megabytes coming from additional Android libraries you’ve decided to include in your project.

Since webpack only optimizes JavaScript code (yes, that includes Angular + TS), it is a bit unrealistic that your scripts, comprising the remainder of the APK size, when shrank, will reduce the package size to half what it was originally.

If you want to further optimize the package size you should consider building in --release configuration. If you are feeling particularly adventurous today you can build with Android ABI splits - this will produce 2/3 separate APKs each containing a smaller runtime package (8mb?), which you will then have to upload separately to the Play Store.
https://docs.nativescript.org/publishing/publishing-android-apps#apks-with-abi-splits


#3

Ok. I have tried doing a --release version with this from the terminal:

npm run build-android-bundle – --release --keyStorePath “~/path/to_key.keystore” --keyStorePassword “thePassword” --keyStoreAlias “theAliasName” --keyStoreAliasPassword “thePassword”

but ended up with this error:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:processF0F1F2F3F4F5F6ReleaseManifest’.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(25.3.1) from [com.android.support:design:25.3.1] AndroidManifest.xml:27:9-31
is also present at [com.android.support:appcompat-v7:26.0.0-alpha1] AndroidManifest.xml:27:9-38 value=(26.0.0-alpha1).
Suggestion: add ‘tools:replace=“android:value”’ to element at AndroidManifest.xml:25:5-27:34 to override.

I am trying to understand what this means but could someone assist?


#4

Different plugins seem to impose their own android support plugin versions. Adding the following in your app.gradle might help. Make sure you clean up the platform (to ensure no previous build artifacts persist) by removing and readding it.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}

#5

Ok, I will try this. Could you what this code does?


#6

The SO post above is where the snippet comes from, if you are interested on reading up on the whole post.

The snippet itself iterates over all dependencies and hard-codes a version, thus normalizing the versions across multiple dependencies in your project.


#7

Thank you , it worked.