2012-07-13 26 views
1

我正在開發一個使用一些本機代碼的Android應用程序。我使用的本地庫有兩個變體,一個用於ARM v6架構,一個用於v7。因此,在我的libs文件夾中,我有兩個文件夾,v6 lib的'armeabi'和v7 lib的'armeabi-v7a'。這裏的主要問題是這個lib大約是8MB,所以我有16mb的庫文件,這些庫中只有一個是需要的,這取決於設備 - 我有8mb的膨脹,這使得我的apk很大。多個APK的不同本機代碼

如果我創建了2個不同版本的代碼,一個是v6 lib,另一個是v7 lib,版本代碼不同,Google Play不會識別這兩個apk之間的設備支持差異,並嘗試替換一個與另一個。

我見過this發問,討論這個問題,但沒有解決方案提供。

我該如何獲得Google Play讓這兩個APK互相發佈?

任何幫助將不勝感激。

+0

同樣的問題,用不同的答案:http://stackoverflow.com/a/20029256/192373 – 2014-06-04 06:23:55

回答

2

這不(可)。參閱http://developer.android.com/guide/google/play/publishing/multiple-apks.html#SupportedFilters

支持的過濾器[...]

  • 紋理的OpenGL壓縮格式 [...]
  • 屏幕尺寸(和任選地,屏密度) [...]
  • API級0​​[...]

其它清單元素啓用Google Play過濾器(但未列在上面)仍照常應用於每個APK。 但是,Google Play不允許您根據它們的變體發佈多個APK。因此,如果上面列出的每個APK的過濾器都相同(但APK根據清單文件中的其他特徵而不同),則無法發佈多個APK。例如,您無法提供完全不同於特性的不同APK。

編輯:一個解決方案,它在我腦海中是基於插件:您部署一個應用程序與核心邏輯,UI,和所有的東西,並提供其與同一證書籤署,但只包含幾個不同的「應用程序」本地庫。 MXPlayer使用此方法來支持不同的體系結構,而不會膨脹singel APK:https://sites.google.com/site/mxvpen/download(請參閱「編解碼器」一節)。

+0

是在「插件」的解決方案是,我採用的方法,當應用程序啓動它檢查CPU架構然後下載所需的庫。謝謝 – 2012-07-13 12:51:46

0

在我的情況下,我在同一個APK中編譯了不同的庫,並對它進行了編程,這有助於減小尺寸。但差別不大,但有幫助。

此外,我不知道這是否會滿足您的需求,但如果你想有不同的APK不一定,我認爲不同的包名會做,但再次建議將去一個單一的APK。

這是我的一小段信息,欲瞭解更多信息和幫助,請告訴我。

+0

不同的軟件包名稱意味着兩個完全獨立的應用程序在谷歌播放這遠非理想 - 感謝職業警衛提示,我會看到什麼區別它可以使 – 2012-07-13 12:49:58

-1

其可能的現在,參考此鏈接。

https://developer.android.com/studio/build/configure-apk-splits.html

UPDATE:

您需要添加Android的標籤內的模塊級的build.gradle下面的代碼:

splits 
{ 

     // Configures multiple APKs based on ABI. 
     abi { 

      // Enables building multiple APKs per ABI. 
      enable true 

      // 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 "x86", "armeabi-v7a", "mips" 

      // Specifies that we do not want to also generate a universal APK that includes all ABIs. 
      universalApk false 
     } 
} 

這會給你多個APK爲不同的上傳建築。根據Android:

不同的Android手機使用不同的CPU,這反過來又支持 不同的指令集。 CPU和指令 集合的每個組合都有其自己的應用程序二進制接口(即ABI)。 ABI 非常精確地定義應用程序的機器代碼 應該如何在運行時與系統進行交互。

另外,請記住用不同的versionCode推動兩個apks。一個方便的方法是使用以下腳本,以後在同一個url上提供:

// Map for the version code that gives each ABI a value. 
ext.abiCodes = ['armeabi-v7a':1, mips:2, x86: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 
    } 
    } 
} 

這會在分割代碼下面進行。這使您與您的一部開拓創新的版本代碼乘以上面的腳本中abiCodes數組給定的架構代碼多個APK。例如:如果你的版本代碼爲5,MIPS構建代碼是,如果你universalApk是在分裂碼真2005年通用APK也將被創建。的可以是fallover APK的情況下沒有架構構建APK是發現對於特定設備。

相關問題