android-discuss icon indicating copy to clipboard operation
android-discuss copied to clipboard

如果方便的在gradle 打包的时候移除多余的so .

Open hnlbxb2004 opened this issue 9 years ago • 5 comments

一些第三方的库现在包含了有很多so ,am 的 x86 的,mips 的等,比如我只需要am 的,那么怎么在打包的时候移除的这些其他的?这个第三方库我是用gradle 依赖的aar 包。

hnlbxb2004 avatar May 07 '16 06:05 hnlbxb2004

@hnlbxb2004

defaultConfig {
    applicationId "x"
    minSdkVersion 14
    targetSdkVersion 22        
    versionCode 16
    versionName "x"
    signingConfig signingConfigs.config
    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86"  // 指定要ndk需要兼容的架构(这样其他依赖包里mips之类的so会被过滤掉)
    }
}

atearsan avatar May 07 '16 06:05 atearsan

The method provided by @atearsan will package only a single ABI to the final apk. If I want to keep armeabi-v7a and arm64-v8a and remove the others. How can I do that? The following is my solution.

    Set<String> excludePaths = new HashSet<>();
    String[] excludeFiles = ["liba.so", "libb.so", "libc.so", "libd.so", ...]; // more libraries go here
    String[] excludeABIs = ['armeabi', 'mips', 'x86', 'x86_64']
    excludeABIs.each { abi ->
        excludeFiles.each { solibrary ->
            excludePaths.add("lib" + File.separator + abi + File.separator + solibrary)
        }
    };

    packagingOptions {
        setExcludes(excludePaths)
    }

WanghongLin avatar Jun 12 '16 09:06 WanghongLin

本人使用的是这一种:

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ndk {
                abiFilters "armeabi", "armeabi-v7a", "arm64-v8a" // 保留这三种架构的CPU
            }
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            ndk {
//                abiFilters "armeabi", "armeabi-v7a", "arm64-v8a" // 保留这三种架构的CPU
//            }
        }
    }

aohanyao avatar Oct 19 '16 08:10 aohanyao

怎么自动对齐 so 数目呢,就是 比如检测到 armeabi-v7a 不存在 a.so,而在 armeabi 中存在的话,打包的时候自动复制一个到 armeabi-v7a 目录下

biaomingzhong avatar Mar 06 '18 07:03 biaomingzhong

https://stackoverflow.com/a/50405679/6197774

ddyos avatar May 18 '18 07:05 ddyos