2017-12-30 60 views
3

Apk 크기를 줄이려면 각 CPU 아키텍처마다 다른 apk를 만들어야합니다. 이것이 제가 사용하고있는 접근법입니다.다른 app 파일을위한 다른 버전 번호를 다른 CPU 아키텍처로 만드는 방법

splits { 
    abi { 
     enable true 
     reset() 
     include 'x86', 'armeabi-v7a', 'armeabi' 
     universalApk false 
    } 
} 

이렇게하면 두 apk 파일이 만들어지며 두 파일 크기는 universalApk보다 작습니다. 그래서이 내 APK 크기 문제를 해결.

이제는 두 파일을 모두 Play store에 업로드하는 방법이 있습니다.

This은 모두 apk's의 버전 코드가 달라야한다고 명시했습니다.

업데이트 된 apk를 playstore에 추가하기 전에 앱 수준 build.gradle과 업데이트 versionCode 속성을 엽니 다.

defaultConfig { 
     versionName "1.0.2" 
     versionCode 78 
    } 

그래서 지금은 여러 APK의를 만들 때, 모두 versionCode 동일해야합니다. 제 질문은 어떻게 생성 된 apk의 두 가지에 다른 versionCode를 할당 할 수 있습니까? 아니면 둘 다 자신의 versionCode 값을 변경 한 후 apk의 것을 하나씩 생성해야합니까?

답변

2

예는

가 여기에 다른 버전의 코드와 3 개의 APK 파일을 만들어 내 Gradle을 파일입니다 수 있습니다. 아래의 gradle 파일에서 귀중한 의견을 찾을 수 있습니다.

apply plugin: 'com.android.application' 

android { 

    splits { 
     abi { 
      enable true 
      reset() 
      include 'x86', 'armeabi-v7a', 'armeabi' 
      universalApk false 
     } 
    } 
    signingConfigs { 
     release { 
      keyAlias 'androiddebugkey' 
      keyPassword '' 
      storeFile file('/Users/anasabubacker/StackOverflow/signing/ekAndroid_debug.keystore') 
      storePassword 'Android' 
     } 
    } 
    compileSdkVersion 26 
    buildToolsVersion "27.0.2" 
    defaultConfig { 
     applicationId "lib4.com.stackoverflow" 
     minSdkVersion 17 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     debug { 
      debuggable false 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      proguardFile '/Users/anasabubacker/StackOverflow/proguard-android.txt' 
     } 
    } 
} 

// Map for the version code that gives each ABI a value. 
ext.abiCodes = ['armeabi-v7a':1, x86:2, armeabi:3] 

// For per-density APKs, create a similar map like this: 
// ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3] 

import com.android.build.OutputFile 

// For each APK output variant, override versionCode with a combination of 
// ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode 
// is equal to defaultConfig.versionCode. If you configure product flavors that 
// define their own versionCode, variant.versionCode uses that value instead. 
android.applicationVariants.all { variant -> 

    // Assigns a different version code for each output APK 
    // other than the universal APK. 
    variant.outputs.each { output -> 

     // Stores the value of ext.abiCodes that is associated with the ABI for this variant. 
     def baseAbiVersionCode = 
       // Determines the ABI for this variant and returns the mapped value. 
       project.ext.abiCodes.get(output.getFilter(OutputFile.ABI)) 

     // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes, 
     // the following code does not override the version code for universal APKs. 
     // However, because we want universal APKs to have the lowest version code, 
     // this outcome is desirable. 
     if (baseAbiVersionCode != null) { 

      // Assigns the new version code to versionCodeOverride, which changes the version code 
      // for only the output APK, not for the variant itself. Skipping this step simply 
      // causes Gradle to use the value of variant.versionCode for the APK. 
      output.versionCodeOverride = 
        baseAbiVersionCode * 1000 + variant.versionCode 
     } 
    } 
} 


dependencies { 
    implementation fileTree(include: ['*.jar'], dir: 'libs') 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support:design:26.1.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
}