2017-03-01 57 views
2
splits { 

     // Configures multiple APKs based on screen density. 
     density { 
      // Configures multiple APKs based on screen density. 
      enable true 

      reset() 
      // Specifies a list of screen densities Gradle should create multiple APKs for. 
      include 'ldpi', 'mdpi', 'hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi' 
      // Specifies a list of compatible screen size settings for the manifest. 
      //compatibleScreens 'small', 'normal', 'large', 'xlarge' 
     } 
     // Configures multiple APKs based on ABI. 
     abi { 
      // Enables building multiple APKs per ABI. 
      enable false 
      // By default all ABIs are included, so use reset() and include to specify that we only 
      // want APKs for x86, armeabi-v7a, and mips. 
      // Resets the list of ABIs that Gradle should create APKs for to none. 
      reset() 
      // Specifies a list of ABIs that Gradle should create APKs for. 
      include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 
      // Specifies that we do want to also generate a universal APK that includes all ABIs. 
      universalApk true //generate an additional APK that contains all the ABIs 

      //'armeabi' - Not surported by Realm since v2.0.0 
     } 
    } 

我試圖拆分我的APK由Desity爲了減少APK大小,使用上面的Gradle它將APK分成密度,但每個APK的可繪製資源是相同的。Android工作室拆分APK在密度

這應該不是xhdpi APK只包含drawable-ldrtl-xhdpi-v17,drawable-xhdpi-v4和mipmap-xhdpi-v4的結果嗎?

+0

你有你所有的繪圖資源作爲xxxhdpi版本?這不是必需的。查看https://developer.android.com/guide/practices/screens_support.html#support中的第一個提示,這可以顯着降低您的APK大小。另外,你可以考慮讓ldpi繪製出來。它們可以從mdpi縮小。 – EarlGrey

+0

不,我們只有xml drawables,我們不能vectorDrawables.useSupportLibrary = true因爲其他依賴關係 –

回答

0

的gradle中密度APK分裂的例子:

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion 19 
    buildToolsVersion = rootProject.ext.buildToolsVersion 
    defaultConfig { 
    versionCode 12 
    minSdkVersion 16 
    targetSdkVersion 20 
    buildConfigField "String", "FOO", "\"bar\"" 
    } 
    splits { 
    density { 
     enable true 
     exclude "ldpi", "tvdpi", "xxxhdpi", "400dpi", "560dpi" 
     compatibleScreens 'small', 'normal', 'large', 'xlarge' 
    } 
    } 
} 
// map for the version code 
ext.versionCodes = [all:1, mdpi:2, hdpi:3, xhdpi:4, xxhdpi:5] 
android.applicationVariants.all { variant -> 
    // assign different version code for each output 
    variant.outputs.each { output -> 
    def key = output.getFilter(OutputFile.DENSITY) == null ? "all" : output.getFilter(OutputFile.DENSITY) 
    output.versionCodeOverride = project.ext.versionCodes.get(key) * 100 + android.defaultConfig.versionCode 
    } 
}