Why is apk generated by studio smaller than command line apk - android

OS : Mac os
Gradle 3.0
APK generated by studio : 13 Mb
APK generated by command line using "gradle assembleDebug" : 21 Mb.
Its almost double the size for the same project with the same build.gradle file.
I have used
aaptOptions
{
cruncherEnabled = true
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Any idea if there are parameters being passed specifically by Studio which help reduce the size?

If you build APK in Android studio connecting the phone, then Android studio removes all the resources from your drawable folder which is not applicable to that phone. That's the reason APK generated by Android studio looks smaller.
Try this, connect different resolution phone, HDPI, MDPI, XXHDPI phones while building your APK. You can find different size of APKs generated

Related

Libgdx - Gradle Android debuggable

I would like to make my app debuggable.
When I deploy to my nexus 5x I get this error:
Error running AndroidLauncher: Cannot debug application from module android on device lge-nexus_5x-(code here). This application does not have the debuggable attribute enabled in its manifest. If you have manually set it in the manifest, then remove it and let the IDE automatically assign it. If you are using Gradle, make sure that your current variant is debuggable.
If I add the debuggable="true" attribute to the android tag in my manifest it works.
But I'm forgetful, so I'd rather do it the proper way with gradle.
I've tried to add a lot of the things I've found on the internet to both my Android module build.gradle, and my project's root level build.gradle.
All to no avail.
What should work?
Thanks,
Chase
On an tangent, I also tried running my HTML module using the instructions from their site, and it says it's failing because I'm using java 1.7 features but the gradle source is 1.6. I've also tried googling that to no avail. I was adding some lines like this:
sourceCompatibility 1.7
targetCompatibility 1.7
You can use build types (Build Variants) in your android gradle file:
project/android/build.gradle
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
minifyEnabled true
pseudoLocalesEnabled false
debuggable false
signingConfig signingConfigs.AndroidKey
}
}
* There is some proguard stuff and signing config you might not need. Just remove from the release build variant.
You don't need any other configuration in other files. You can see the full source I used in my project here.
If you are using Android Studio you can change between your build variants here:
When you run the project if release is selected it will install the non debugable apk in your device. Otherwise, if debug is selected it will install the debugable apk. Both can be installed at the same time. It will show the app twice in your device.
The problem is that it should be debugable by default. You could remove the debuggable true line and the debug build variant should still be debugable.
If it does not work paste your manifest and your build.gradle files here so we can see what is going on.
You can look all theses files in my project. It is also a libGDX project, but it don't have the HTML module.
The Build Variant docs might be helpful.

How to decrease React-Native android App Size

For my react native android app, size of codes I have written is only 12KB
But package generated is of size 7.9MB. How can i decrease that.
As per Documentation for react native, I have already enbabled proguard on file app_root/android/app/proguard-rules.pro but size of didn't decrease
...
android {
...
buildTypes {
release {
...
minifyEnabled true
}
}
}
...
Is there a solution available for this?
React Native app APKs include JSCore binaries for x86 and ARM. If you don't need x86 you could reduce the size to 3-4 MB.
1)In your app/build.gradle set
def enableSeparateBuildPerCPUArchitecture = true
2)remove x86 from abiFilters
this helped me in reducing size from 7.8 mb to 4.5MB
Android devices support two major device artitectures armebi and x86. By default RN builds the native librariers for both these artitectures into the same apk.
Open up android/app/build.gradle :
Set def enableProguardInReleaseBuilds = true,
this would enable Progaurd to compress the Java Bytecode. This reduces the app size by a lil bit
And,
Set def enableSeparateBuildPerCPUArchitecture = true .
And check in android/app/build/outputs/apk/ - you will receive two apk files for armebi and x86 with approx half size of original apk.
There are a couple of techniques in order to reduce your APK size:
Split your app by architecture, you can split your APK by a list of well-known architectures: armeabi-v7a, x86, arm64-v8a, x86_64
if you're distributing your application, using the play store it's a good idea to do it with the Android app bundle.
Enabling prodguard will result in a lower size of the APK.
Optimize your image assets, and if there's a chance try using SVG assets as much a possible.
There have been a change in the size of the resulted APK in React-Native 0.62 by enabling the new JavaScript engine which reduce the size of the native libs almost 40% Hermes Engine
These stats below are from Hermes engine and also mention the APK size reduction.
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
shrinkResources true
ndk {
abiFilters "x86", "armeabi-v7a" //this will help you to shrink your app size in release build
}
}

Generated APK size increased in Android Studio

I switched my IDE from eclipse to android studio and generated apk after some very minor changes (No class or files were added).
The APK generated from eclipse was around of size 3 MB but when I generated APK from android studio, the apk size was around 5.5 MB.
I even tried to clean and generate APK in Release mode but still APK size was same i.e. 5.5 MB.
Is there any specific reason behind this in android studio or am I missing something ?
your problem certainly have nothing to do with Android Studio or Eclipse. It's todo with Gradle and Ant. Those are the built systems used by each respectively.
On a general approach it seems to be that the Ant build was using ProGuard to remove unused resources and classes whilst your build.gradle file is not instructing Gradle to do the same.
Trying adding the minifyEnabled to your release build, like in the example below.
PS: change the name of the proguard file to the one on your project
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

Upgraded to Android Studio 1.0 & Gradle 1.0.0, aapt makes PNG images larger if pre-optimized

I performed an upgrade to Android Studio 1.0 & Gradle 1.0.0 today, from Android Studio 0.86 & Gradle 0.13. Prior to the upgrade, I was using "runProguard = true" option in my release builds extensively, to reduce my APK size to just under 50 MB, to meet Google Play Store's APK size restrictions.
However, with the new Android Studio 1.0 / Gradle 1.0.0 with "minifyEnabled = true", I am seeing resulting APKs at 55.6 MB, which is significantly larger than before. The debug build APKs are resulting in 55.6 MB as well, leaving me to conclude that the minifyEnabled option isn't actually working.
I've updated my Gradle configuration to work with the new Gradle version and is listed below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
signingConfig signingConfigs.release
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.+'
compile 'it.sephiroth.android.library.picasso:picasso:2.3.4.3'
}
As far as I can see, everything seems to be okay with the build.gradle file, but minifyEnabled just doesn't seem to work. What's strange is that there are no compilation errors reported when I generate the release build. Does anyone have any ideas on how to get minifyEnabled to work?
EDIT (12/10/2014):
Alright, it appears that this issue is not related to minifyEnabled at all, but to an older bug with aapt that was previously resolved with Gradle 0.9.1, where aapt would increase the size of PNG files if they were already pre-optimized.
http://tools.android.com/tech-docs/new-build-system
The bug has resurfaced with Gradle 1.0.0. This bug can be reproduced by doing the following:
Optimize PNG files with TinyPNG or other PNG optimization tools.
Use Android Studio 1.0 with Gradle 1.0.0.
Compile Android project with or without aaptOptions newPNG flag.
Open APK file and compare PNG files against original PNG files for size.
The issue has been reported on the AOSP tracker and they seem to be aware of it: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=tinyPNG&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=65335
FYI, this post should probably be merged with this previous StackOverflow post, as it is exactly this same old problem: Export signed app without "optimizing" png images

Android Studio ProGuard does not appear to run

I switched over from Eclipse to Android Studio in the last few days and have gotten most everything working. However, when I generate a signed APK it appears as though ProGuard is never running.
I am using the Generate Signed APK Wizard, selecting 'Run ProGuard' and specifying my proguard.cfg as the config file. The build process runs without errors and generates a functional apk, but that apk is 65% larger than the one generated by Eclipse. When I generate the apk through Android Studio's APK Wizard and do not select 'Run Proguard' the resulting apk is the same size as the one that should have had ProGuard run on it. No mapping.txt, seeds.txt, or usage.txt is generated anywhere in my project directory. I have tried adding
buildTypes {
release {
runProguard true
proguardFile file('proguard.cfg')
proguardFile getDefaultProguardFile('project-android.txt')
}
}
and variations to my build.gradle file but that has had no effect either.
This is occurring on Android Studio 0.2.0, though I was seeing the same behavior on 0.1.9. I am working on Windows 7.
Can anyone tell me what might be going on? I would be happy if I could find the logs ProGuard is supposed to generate.
Just update your build.gradle
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Details Reference.
I hope it will helps you
Happily, I have found a solution. The issue was that before creating the signed apk, I had modified the package name in the AndroidManifest in order to overwrite a particular build in the Google Play Store. However, this change of package name had not refactored all of the corresponding "import 'package name'.R;" lines throughout the code. Today, after re-importing the project, it would no longer build because of errors attempting to import R. Once I modified all the import lines, not only did my project build properly, but exporting the signed apk properly ran ProGuard.
I'm guessing that Android Studio was somehow caching the "import R" lines and that when ProGuard was attempting to run it did not have those cached values and then crashed. Why there was no error output for me to see, I do not know.
**in new Gradle system**
BuildType.runProguard -> minifyEnabled
BuildType.zipAlign -> zipAlignEnabled
BuildType.jniDebugBuild -> jniDebuggable
BuildType.renderscriptDebug -> renderscriptDebuggable
ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode -> renderscriptNdkModeEnabled
or visit at
http://tools.android.com/tech-docs/new-build-system

Categories

Resources