Nativescript: Huge Angular2 apk size

Created on 20 Apr 2017  路  6Comments  路  Source: NativeScript/NativeScript

After building HelloWorld Angular2 app, the apk size is about 17.5 mg. That is very huge for a simple app. Searched a lot and found this solution (using webpack) in an issue. The result was about 11.1 mg but still big enough. Any idea?

Version numbers

  • CLI: 2.5.2
  • Cross-platform modules: 2.5.2
  • Runtime(s): 2.5.0
  • Plugin(s): No plugins yet.
android question

Most helpful comment

@vahidvdn

Huge part of the apk is the runtime itself that takes care of running all your JavaScript. The android runtime consists of c++ code which compiles for different mobile ABIs (x86, armeabi-v7a, x64). The result is a package containing all 3 chunks bundled in one APK. You could provide additional configuration in your app.gradle inside app/App_Resources/Android to build 3 separate APKs (4-5mbs each) to upload to the Google Play Store.

Currently supported: Using runtime version 2.5 you can place the following inside the android { defaultConfig { ... } } (the defaultConfig) closure. Change the value from x86 to armeabi-v7a and rebuild to output an apk with the distinct ABIs. Will require a separate build for each APK

  defaultConfig { 
    ...
    //override supported platforms
    ndk {
           abiFilters.clear()
            abiFilters "x86"
    }
  }  

Recommended: If you'd like to use tns-android@next (or available beginning with version 3.0)
Consider copying the following closure inside your android { } object in app.gradle A single build will output an APK for each ABI included

    splits {
        abi {
            enable true //enables the ABIs split mechanism
            reset() //reset the list of ABIs to be included to an empty string
            include 'armeabi-v7a', 'x86' //what abi to spliy by
            universalApk false //don't include an apk that uses all abis combined
        }
    }

All 6 comments

@vahidvdn,

Have you tried webpack with uglify or without it?

@vahidvdn

Huge part of the apk is the runtime itself that takes care of running all your JavaScript. The android runtime consists of c++ code which compiles for different mobile ABIs (x86, armeabi-v7a, x64). The result is a package containing all 3 chunks bundled in one APK. You could provide additional configuration in your app.gradle inside app/App_Resources/Android to build 3 separate APKs (4-5mbs each) to upload to the Google Play Store.

Currently supported: Using runtime version 2.5 you can place the following inside the android { defaultConfig { ... } } (the defaultConfig) closure. Change the value from x86 to armeabi-v7a and rebuild to output an apk with the distinct ABIs. Will require a separate build for each APK

  defaultConfig { 
    ...
    //override supported platforms
    ndk {
           abiFilters.clear()
            abiFilters "x86"
    }
  }  

Recommended: If you'd like to use tns-android@next (or available beginning with version 3.0)
Consider copying the following closure inside your android { } object in app.gradle A single build will output an APK for each ABI included

    splits {
        abi {
            enable true //enables the ABIs split mechanism
            reset() //reset the list of ABIs to be included to an empty string
            include 'armeabi-v7a', 'x86' //what abi to spliy by
            universalApk false //don't include an apk that uses all abis combined
        }
    }

@sis0k0 I tried webpack without uglify.

@Pip3r4o Thanks for the reply. I will try your solutions. For now, I'm going to close this issue.

@Pip3r4o I added the following code to the android { defaultConfig { ... } }

ndk {
          abiFilters.clear()
            abiFilters "armeabi-v7a"
 }

But the result is only one APK with size of 13 mg.

to build 3 separate APKs (4-5mbs each)

How should I achieve this?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings