gpt4 book ai didi

android - facebook sdk 的 Proguard 配置。剥离除分析之外的所有内容

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:04:58 26 4
gpt4 key购买 nike

我只想使用 facebook sdk 进行分析,是否有优化的 proguard 配置可用于去除其余部分?

最佳答案

当涉及到巨大的规模时,它主要是关于资源而不是担心最小化 java 代码本身。所以您实际上可以尝试下面提到的一些事情。

  1. Proguard 处理 Java 代码。不幸的是,它不适用于资源文件夹。因此,如果未使用 res/drawable 中的图像 my_image,Proguard 只会剥离它在 R 类中的引用,但会保留相关图像。
  2. Lint 是一种静态代码分析器,只需简单地调用 ./gradlew lint 即可帮助您检测所有未使用的资源。它会生成一个 HTML 报告,并在“UnusedResources:未使用的资源”部分下为您提供看起来未使用的资源的详尽列表。只要您不通过代码中的反射访问这些资源,就可以安全地删除它们。

但是 Lint 可以告诉您未使用的资源在哪里,但是使用 fb sdk 很难删除资源,因为它来自 maven 存储库。

最小化资源配置(build.gradle)例如,Fb sdk 提供了对您可能不需要的所有语言的支持,或者对您可能没有用的所有文件夹图像(如 mdpi)的支持。

defaultConfig {
resConfigs "en", "de", "fr", "it"
resConfigs "nodpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
}

如果所有这些都不起作用,则意味着 native 代码正在膨胀您的 apk,其中应用程序二进制接口(interface)拆分可能有助于减小您的 apk 大小。

ABI 拆分:-

 splits {
density {
enable true
reset()
include "ldpi", "mdpi"
}
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
}
}

我认为当我打开 facebook sdk gradle 文件时可以在这里做一些事情......它几乎没有传递依赖性,这是多余的并且可能与你的支持版本冲突所以你可以在你的文件中导入相同的内容

dependencies {
// Facebook Dependencies
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:customtabs:25.3.1'}

它可以从最终的 fat jar 中删除,因为您可能已经在您的项目中使用了太多不同或冲突的支持依赖项..因此您可以理想地根据您的要求排除传递依赖项,如下所示

compile ('com.facebook.android:facebook-android-sdk:4.+') {
exclude group: 'com.android.support' //by group
}

关于android - facebook sdk 的 Proguard 配置。剥离除分析之外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45139123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com