things that affect the apk file size - android

what are the ways to reduce the apk file size?
and what are the things affecting it?
I noticed sometimes when I build the apk, the size goes above 100k and other times it will be around 20k what is the thing it depends on exactly?
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.dynamiclist"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.karumi:dexter:6.0.2'
api 'com.otaliastudios:cameraview:2.6.1'
implementation 'com.google.firebase:firebase-ml-vision:24.0.1'
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2'
implementation('com.journeyapps:zxing-android-embedded:3.6.0')
implementation 'com.android.support:multidex:1.0.3'
}
this is the gradele that I have used when it reached 100k if that helps

First you have to Analyse the apk file which gives the information of how much Size allocated to the Resources......
so for analyze apk for Build Apk using:-
Build > Build Bundles(s)/APK(s) > Build APK(s).
After the Build Apk you can analyse your apk using:-
Build > Analyze APK...
this will Gives you the information about the Size are taken by Resources.
using which you can Remove unwanted Resources for Decrease Apk size.
I am sure This will Help you for Decrease The Apk Size..

Related

NoClassDefFoundError: Failed resolution of: Lokhttp3/logging/HttpLoggingInterceptor;

I have an aar library project, I am using it in a sample project. I added the relevant library to Maven Local Repository. When I check the Pom file, I can see it as Okhttp3 / logging / HttpLoggingInterceptor dependency. But i am facing with below screen shoot error. Any suggestions?
my parent app gradle file looks like above code
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.deneme"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.6'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.mylibrary:feature:1.0.15#aar'
implementation 'com.android.support:multidex:1.0.3'
}
My problem is that when the pom file is generated it generates incorrectly, I am actually having a problem on the wrong sub-mobule. After I fixed my pom settings my problem was resolved.

In Android studio unable import the kotlin. Could not download kotlinx-coroutines-core-1.3.7.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7)

When i'm creating the kotlin project build is failing due to
What went wrong:
A problem occurred configuring root project 'SampleFirstApp'.
Could not resolve all artifacts for configuration ':classpath'.
Could not download kotlinx-coroutines-core-1.3.7.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7)
> Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-coroutines-core/1.3.7/kotlinx-coroutines-core-1.3.7.jar'.
> Could not GET 'https://d29vzk4ow07wi7.cloudfront.net/ad426ec76f52b1dcdf200f55495aea9a2d2796811884e8c4b514645061cf59f3?response-content-disposition=attachment%3Bfilename%3D%22kotlinx-coroutines-core-1.3.7.jar%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvYWQ0MjZlYzc2ZjUyYjFkY2RmMjAwZjU1NDk1YWVhOWEyZDI3OTY4MTE4ODRlOGM0YjUxNDY0NTA2MWNmNTlmMz9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmtvdGxpbngtY29yb3V0aW5lcy1jb3JlLTEuMy43LmphciUyMiIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTYwMDA3NzM5N30sIklwQWRkcmVzcyI6eyJBV1M6U291cmNlSXAiOiIwLjAuMC4wLzAifX19XX0_&Signature=QWeAM~fwvUMegI6EgefXgSAV0Cd6m~ULFAMUE2DboAuh1jEkoNp2tE-vpfsgBiehCl5ECs1t96jQrP26I3gGCfeWG-rX1qWAmrMfxESzhPjlvQWs5jOLLuFt8tlnuw6YJeUAbMRlV5mgUXv4~NhqxZ3qhT9XsN3XlTHJXIEKNkyjymJfdWgk2RRFyNFs3aRNIBwPJoNIRx6QiLeYf2MmL43jTxvS~moILHqWwtIoS5G6ObVtLVmOvaCN0QxApaBtcSytM3PKAfaGhnSJoCUCu4G~8d03tMfXdqnH6BsQ7Th1BLTOSQQaI3y8Z2s9xpv9ZsRmm3bJ0lC5oC~63lpjSg__&Key-Pair-Id=APKAIFKFWOMXM2UMTSFA'.
this error is coming
My kotlin version in studio is 1.4.10. I have tried all solutions available in google and SO. I have invalidate and cache studio and clean and rebuild the application.
My gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.e.samplefirstapp"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Android app works in debug but not in release, idk why

The login with Twitter works ins debug, but not in release, also the size of the apk is bigger in the debug.
Where is the problem??
i have 3 activitys
this is the build.grandle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.PolDevs.MyClickerGame"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.firebase:firebase-auth:19.1.0'
implementation 'com.google.firebase:firebase-database:19.1.0'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.twitter.sdk.android:twitter-core:3.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
Open the documentation for all the libraries you are using and double check if they have any specific rules to be put in proguard since that is enabled during release build. proguard obfuscates you’re APK when making a release build, which means removing code like annotations and comments etc. which also reduces the size of the apk.
So for some libraries to work, you have to specify some rules in your proguard file to no obfuscate certain things. Common error to be careful of when maiking debug and release builds.

getTitle,getDescription,createPendingIntent(), getLargeIcon() missing in Playback Notifications with ExoPlayer

I am trying to implement Playback Notifications with ExoPlayer. But getTitle,getDescription,createPendingIntent(), getLargeIcon are missing and android studio is showing red (Cannot resolve method). How can i get these?
I wrote my code exactly same as the link. I tried it multiple times.
This is my build.gradle file (if required):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mediaplayertest"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "com.android.support:support-media-compat:28.0.0"
implementation "com.android.support:support-compat:28.0.0"
implementation 'com.google.android.exoplayer:exoplayer:2.9.5'
}
You need to define the gradle implementation correctly.
From The hello world example
implementation 'com.google.android.exoplayer:exoplayer-core:2.X.X'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.X.X'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.X.X'
In your gradle build script you have asked for the just "exoplayer"
NOTE: that for the PlaybackNotificationManager class you will need exoplayer-ui meaning for that particular class you would just need
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.5' but I would also include exoplayer-core

Android Studio compile error:com.android.dex.DexException: Multiple dex files define Ljava_cup/runtime/ComplexSymbolFactory

I get this error when trying to compile an android studio project, that uses the "weka" machine learning algorithm. The project is part of an uni assignment, just to be clear.
the build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ac.univie.em2.project"
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '26.0.2'
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// https://mvnrepository.com/artifact/nz.ac.waikato.cms.weka/weka-stable
implementation 'nz.ac.waikato.cms.weka:weka-stable:3.8.0'
}
Things we already tried:
1) adding the multidexenabled true flag
2) clean and rebuild
EDIT: We found a workaround, by not using maven for the weka dependency, but using the 3.6.6 jar directly. I would still love it if someone could tell me what the problem in out build.gradle file is

Categories

Resources