2016-03-15 30 views
6

我正面臨着這個似乎無法解決的問題。這裏是場景:針對具有ABI分割的特定體系結構的Gradle依賴關係

Im建築apk使用gradle依賴關係和這個依賴關係是特定的體系結構所以對於x86的x86我需要不同的依賴關係和不同的手臂。

我的產品口味解決它:

productFlavors { 

    dev { ... } 
    develx86 { ... } 
    production { ... } 
    productionx86 { ... } 

} 

於是我這樣定義的依賴性:

develCompile 'dependency_for_arm' 
develx86Compile 'dependency_for_x86' 

這工作不錯。但最近我不得不在我的應用程序中添加一個renderscript的用法。我做了這樣:

renderscriptTargetApi 22 
renderscriptSupportModeEnabled true 

並在此之後,當我上傳到谷歌的apk發揮它說,它的APK是適合與ARM,X86。我不知道這是可能的。正如你可以認爲它會在具有不同CPU的設備上崩潰(如果我爲arm生成apk並且用戶將在x86應用程序上執行它將崩潰)。

所以我decited使用ABI分裂:

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

//Ensures architecture specific APKs have a higher version code 
//(otherwise an x86 build would end up using the arm build, which x86 devices can run) 
ext.versionCodes = [armeabi:0, x86:1] 

import com.android.build.OutputFile 

android.applicationVariants.all { variant -> 
    // assign different version code for each output 
    variant.outputs.each { output -> 
     int abiVersionCode = project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) ?: 0 
     output.versionCodeOverride = android.defaultConfig.versionCode + abiVersionCode 
    } 

但現在,當我看到生成APK文件,我的依賴性是當我打開部分風味特異沒有納入APK和APK會崩潰它使用來自這個依賴關係的API。

有人知道如何解決這個問題嗎?或者有人知道爲什麼Google Play會說當我包含renderscript時apk同時適用於兩種體系結構? (沒有它,它正常工作,但我需要renderscript)。

謝謝你的時間。我會感謝任何幫助。

+0

任何運氣?如果你找到答案,請發佈答案 –

回答

0

對不起,我現在還不能評論內聯。

什麼是在apk中,特別是在res/raw /和lib /? 另外,你使用gradle-plugin 2.1.0嗎? (因爲您使用的是renderscriptTargetApi 22),您是否嘗試過構建工具23.0.3?

2

如果你看看你的APK裏面,lib文件夾,你應該看到,renderscript支持模式爲其他體系結構添加了庫,而不是你支持的那個。

您可以使用ABI特定的口味保持您的早期配置。 但爲了確保其他架構沒有庫都包括在內,嘗試添加abiFilters到您的口味:

productFlavors { 

    dev { ... ndk.abiFilters 'armeabi-v7a' } 
    develx86 { ... ndk.abiFilters 'x86' } 
    production { ... ndk.abiFilters 'armeabi-v7a' } 
    productionx86 { ... ndk.abiFilters 'x86' } 

} 
+0

謝謝你,我會盡力讓你知道。 – Sajmon