减少.java文件的数量是否减少了apk的大小?
例如,我最好是在Activity
类中定义我的ListAdapter
,而不是单独的.java文件? 减少apk文件的大小并加入java文件
shape.xml
并在
selector.xml
中引用它或在
item
的选择器内定义该形状?
减少.java文件的数量是否减少了apk的大小?
例如,我最好是在Activity
类中定义我的ListAdapter
,而不是单独的.java文件? 减少apk文件的大小并加入java文件
shape.xml
并在
selector.xml
中引用它或在
item
的选择器内定义该形状?
你最好减少图像资源,如果你正在使用maven/gradle构建系统,你可以通过使用progaurd工具来卸载代码来减小apk大小。
减少.java文件数量是否减少了apk大小?
不一般。
xml文件怎么样?例如make一个shape.xml并在selector.xml中引用它,或者在选择器的项目内定义该形状?
这可能会节省少数几个字节。
我有一些重要的情况,即使是小规模的变化是非常重要的(如〜5KB)
,你使用了tiny摆脱库并使用最小可能的库集(例如,特定的播放服务片段,而不是整个“厨房水槽”播放服务库)
降低您可绘制的密度的变体数量,如果由Android测试自动采样满足您的需求,并使用lint确定可能在项目中挥之不去的资源,你是不是引用
搭配使用ProGuard
在您的摇篮构建文件,如果您使用的是Android工作室和其他一切西里尔Mottier
使用minifyResources
和resConfigs
选择在博客中指出
感谢您的详细解答 –
APK尺寸:
一般来说这取决于您所使用的资产。尝试在android studio中使用LINT,它会给出您可以检查和删除的未使用资源的摘要。
此外,proguard在这方面非常有帮助,请尝试在您的应用程序中使用proguard。
http://dominoc925.blogspot.in/2015/01/enabling-proguard-obfuscation-in.html
使用minifyenabled具有以下ProGuard的基本配置=真我发现某处#1:
-dontwarn org.**
-dontwarn okio.**
-dontwarn com.squareup.**
##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
##---------------End: proguard configuration common for all Android apps ----------
# Remove Logging statements
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** e(...);
public static *** i(...);
}
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.antew.redditinpictures.library.imgur.** { *; }
-keep class com.antew.redditinpictures.library.reddit.** { *; }
##---------------End: proguard configuration for Gson ----------
#QuickBlox
-keep class org.jivesoftware.smack.** { *; }
-keep class com.quickblox.** { *; }
-keep class * extends org.jivesoftware.smack { public *; }
-keep class org.jivesoftware.smack.** { public *; }
-keep class org.jivesoftware.smackx.** { public *; }
-keep class com.quickblox.** { public *; }
-keep class * extends org.jivesoftware.smack { public *; }
-keep class * implements org.jivesoftware.smack.debugger.SmackDebugger { public *; }
内部类作为单独的类文件编译一次,所以我不认为它使一个巨大的生成区别。我不确定是否有一个巨大的XML而不是几个小的对apk的大小也会有影响。 – Setu
对不起,但我有一些危急的情况,甚至小尺寸的变化是非常重要的(如〜5kb) 你是说这不应该是我的担忧? –
对于所有的意图和目的,没有。如果您担心确保apk的最小尺寸,我会使用Android lint的未使用的资源工具。此外,请注意您的图像资源的文件大小,因为这些通常会对APK的膨胀造成最大影响。 –