1

I have an older project that was coded in one of the first releases of Android Studio. The project doesn't have any large assets other than the application icons. The only 3rd party library it used as AdMob SDK 4.3.1. The resulting signed APK was 105 Kb.

Now Google is requiring me to upgrade from AdMob SDK to Google Play Services SDK to continue to serve ads. So I fired up the latest version of Android Studio, converted the project to gradle, referenced the latest Google Play Services SDK and regenerated a signed SDK (release mode). The size was 1595 Kb.

I can't figure out why it is so large and can't find a way to reduce it. I tried excluding libraries like in this answer, but the resulting file size didn't change.

What am I missing?

Here is my gradle file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services-ads:9.6.1'
}


android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
Community
  • 1
  • 1
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • Use the Android Studio APK Analyzer to determine where your space is going. Or, post your `build.gradle` file here, as part of a [mcve]. – CommonsWare Oct 25 '16 at 15:39
  • 1
    ProGuard can help reducing your APK size as it removes unused code. It is worth checking it out. – Doron Yakovlev Golani Oct 25 '16 at 15:41
  • 1
    Did you try to use `com.google.android.gms:play-services-ads` instead of the complete `com.google.android.gms:play-services`? – tritop Oct 25 '16 at 16:19
  • @tritop My gradle references play-services-ads. I also edited the post to include the gradle file. Am I referencing it wrong? – AngryHacker Oct 25 '16 at 18:49
  • @CommonsWare I've posted the gradle file. – AngryHacker Oct 25 '16 at 18:50
  • 1
    Unless you have a lot of JARs in `libs/`, your problem would appear to be from `play-services-ads`. That AAR alone is ~800KB, not counting ~1400KB in transitive dependencies. What is interesting is that one of those transitive dependencies is called `play-services-ads-lite`, which is only ~300KB (plus a ~500KB transitive dependency). So, you might see what scenarios `play-services-ads-lite` could be used in place of `play-services-ads`, if any. – CommonsWare Oct 25 '16 at 19:06
  • @CommonsWare I am not 100% sure what `transitive dependency` means in the android context. Does it mean that it will also have to be included in the APK? – AngryHacker Oct 25 '16 at 19:57
  • 1
    Yes. If you request Library A, and Library A also needs Library B, C, and D, your request for A pulls in all four of those libraries. – CommonsWare Oct 25 '16 at 20:16
  • @CommonsWare You were right on the money. I hooked up the `-lite` version and the size went down by the differences in library size. – AngryHacker Oct 25 '16 at 21:17

0 Answers0