3
我试图鼓励我从SQLite切换到Realm的工作。最大的反对意见是它的应用程序有多大。在Realm之后,编译发布APK从3.5MB跳到7.5MB(4MB差异)。物理设备上的安装后大小似乎有所不同,但Nexus 6P上的漫游大小约为19MB(与SQLite版本相比差异为6MB),Nexus 5上的漫游大小为16MB。无法缩小大小Realm添加到应用程序
这看起来远远大于Realm文档指示I应该期待,但似乎我能做的不多。我试过APK分裂截至https://realm.io/docs/java/latest/#how-big-is-the-realm-library记录,但是当我运行gradlew installDebug命令,我得到这些错误:
Skipping device 'Nexus 5 - 5.1.1' for 'app:release': Could not find build of variant which supports density 480 and an ABI in armeabi-v7a, armeabi
Skipping device 'Nexus 6P - 6.0.1' for 'app:release': Could not find build of variant which supports density 560 and an ABI in arm64-v8a, armeabi-v7a, armeabi
有没有办法让APK拆分工作,所以只有本地代码为给定设备的处理器是否需要,或者我还能做些什么来缩小APK的尺寸?我认识到这并不是一个巨大的,巨大的影响,但它涉及到我的上级,并且增加50%的应用程序的大小非常可观。
的build.gradle文件,在情况下,它可以帮助:
// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
android {
def globalConfiguration = rootProject.extensions.getByName("ext")
compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion")
buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion")
defaultConfig {
applicationId "com.gane"
minSdkVersion globalConfiguration.getAt("androidMinSdkVersion")
targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion")
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
vectorDrawables.useSupportLibrary = false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
lintOptions {
quiet true
abortOnError false
ignoreWarnings true
disable 'InvalidPackage' //Some libraries have issues with this.
disable 'OldTargetApi'
//Lint gives this warning but SDK 20 would be Android L Beta.
disable 'IconDensities' //For testing purpose. This is safe to remove.
disable 'IconMissingDensityFolder' //For testing purpose. This is safe to remove.
}
signingConfigs {
debug {
}
release {
storeFile file('matrix')
storePassword KEYSTORE_PASSWORD
keyAlias 'matrix'
keyPassword KEY_PASSWORD
}
}
buildTypes {
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-debug'
debuggable true
minifyEnabled false
shrinkResources false
// build.gradle testCoverageEnabled true causes debugger to be unable to view local variables/watches
// https://code.google.com/p/android/issues/detail?id=93730
// https://code.google.com/p/android/issues/detail?id=123771
testCoverageEnabled false
ext.enableCrashlytics = false
}
release {
debuggable false
minifyEnabled true
shrinkResources true
testCoverageEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
alpha.initWith(buildTypes.release)
alpha {
minifyEnabled false
shrinkResources false
}
beta.initWith(buildTypes.release)
beta {
minifyEnabled false
shrinkResources false
}
}
splits {
abi {
enable true
reset()
include 'arm', 'arm-v7a', 'arm64', 'mips', 'x86', 'x86_64'
}
}
}
dependencies {
def appDependencies = rootProject.ext.appDependencies
def appTestDependencies = rootProject.ext.appTestDependencies
compile appDependencies.supportAppCompact
compile appDependencies.supportCardView
compile appDependencies.supportDesign
compile appDependencies.supportPercent
compile appDependencies.supportCustomTabs
apt appDependencies.daggerCompiler
compile appDependencies.dagger
compile appDependencies.butterKnife
compile appDependencies.gson
compile appDependencies.okHttp
compile appDependencies.okHttpUrlConnection
compile appDependencies.picasso
compile appDependencies.rxJava
compile appDependencies.rxAndroid
provided appDependencies.javaxAnnotation
provided appDependencies.autoValue
apt appDependencies.autoValue
compile(appDependencies.crashlytics) {
transitive = true;
}
compile(appDependencies.hapiTenantLibrary) {
transitive = true
exclude module: 'android'
exclude module: 'gson'
exclude module: 'okhttp'
exclude module: 'okhttp-urlconnection'
exclude module: 'rxjava'
}
testCompile appTestDependencies.junit
testCompile appTestDependencies.hamcrest
// Robolectric to help us test Android based components (Activity, Service, BroadcastReceivers, etc)
testCompile(appTestDependencies.robolectric) {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
testCompile appTestDependencies.mockito
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' // fixes issue on linux/mac
}
android.applicationVariants.all { variant ->
def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = parent.name
}
if (variant.buildType.name != "debug" && variant.outputs.zipAlign) {
variant.outputs.each { output ->
def timestamp = new Date().format("yyyyMMdd-HHmm", TimeZone.getTimeZone("UTC"));
def newApkName
newApkName = "${appName}-${variant.versionName}-${timestamp}.apk"
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
}
https://github.com/facebook/redex – Abdellah
https://realm.io/docs/java/latest/#how-big-is-the-realm-library – geisshirt
@Abdellah:那也可能有用,但我的目标是让Realm小到Realm文档所说的我可以 –