问题
When i run my app size of apk will 21 MB. even i enabled proguard. i use android studio to run project. in project files src folder has 8.62 MB size and lib folder size is 400 KB size. so how i reduce size of .apk file. Actually .apk file is 8 mb before some days with same images but after paypal integration my app size will increases to 21 mb. size of build folder is 127 MB.
build.gradle(module app) is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.oi.food"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'AndroidManifest.xml'
} }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('libs/httpmime-4.1.1.jar')
compile files('libs/apache-mime4j-0.6.jar')
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.paypal.sdk:paypal-android-sdk:2.14.1' }
回答1:
I solve this issue by adding this code in module app build.gradle file.
android {
packagingOptions{
exclude 'AndroidManifest.xml'
exclude 'lib/arm64-v8a/libcardioDecider.so'
exclude 'lib/arm64-v8a/libcardioRecognizer.so'
exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
exclude 'lib/arm64-v8a/libopencv_core.so'
exclude 'lib/arm64-v8a/libopencv_imgproc.so'
exclude 'lib/armeabi/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
exclude 'lib/armeabi-v7a/libopencv_core.so'
exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
exclude 'lib/mips/libcardioDecider.so'
exclude 'lib/x86/libcardioDecider.so'
exclude 'lib/x86/libcardioRecognizer.so'
exclude 'lib/x86/libcardioRecognizer_tegra2.so'
exclude 'lib/x86/libopencv_core.so'
exclude 'lib/x86/libopencv_imgproc.so'
exclude 'lib/x86_64/libcardioDecider.so'
exclude 'lib/x86_64/libcardioRecognizer.so'
exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
exclude 'lib/x86_64/libopencv_core.so'
exclude 'lib/x86_64/libopencv_imgproc.so'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.paypal.sdk:paypal-android-sdk:2.14.1'
}
回答2:
try
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
shrinkResources true
will not include the images from resources which your using in the final apk
hope this helps
回答3:
You can easily reduce the size of the app by reducing the image size. Please use https://tinypng.com/ to reduce your image size. This will ensure your app size is also reduced. The image quality will remain the same.
Also in case of libraries, please be sure to include ONLY those components that you really need. Also remove any unwanted and unused imports.
回答4:
Before click Finish when open new project wizard, uncheck backward compatibility(appcompat). This is can reduce from 1.5 MB to 180 KB.
回答5:
These 4 things reduce your apk size almost 50-60%
- Replace
proguard-android.txt
withproguard-android-optimize.txt
- Make
minifyEnabled
true
- Add
shrinkResources
true
Add
resConfigs
buildTypes { release { minifyEnabled true shrinkResources true resConfigs "en" proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
Details:
proguard-android-optimize.txt
is the more aggressive progurard configuration thanproguard-android.txt
.shrinkResources
attribute will remove all the resources, those are not used anywhere in the project.resConfigs
attribute will remove all the other localized resources while building the application. Here, it strips other than english resources.
回答6:
I think you should build your APK as (APK bundle), Google promotes that for APK size issues. I've used the option for my projects and it did actually decrease the size of my APK.
回答7:
The Best Way to Reduce The Size of Your APK File is reduce the use of the libaries that are used in build.gradle file . these libaries create a lot of redandancy and in turn increase the size of the project .. enter image description here
来源:https://stackoverflow.com/questions/38887998/paypal-is-not-working-after-removing-io-card