2016-04-18 101 views
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) 
     } 
    } 
} 
+0

https://github.com/facebook/redex – Abdellah

+0

https://realm.io/docs/java/latest/#how-big-is-the-realm-library – geisshirt

+0

@Abdellah:那也可能有用,但我的目標是讓Realm小到Realm文檔所說的我可以 –

回答

1

的問題顯然是雙重的:

  1. 的APK分裂信息不包括用於建立Nexus設備。 Realm已經更新了他們的文檔,以便解決。
  2. 我的Gradle文件有一個添加的部分來重命名APK文件。

現在APK分割工作,這使得APK成爲一個可管理的大小。

相關問題