【问题标题】:Libgdx enable proguardLibgdx 启用 proguard
【发布时间】:2017-04-10 08:47:38
【问题描述】:

我一直想启用 proguard 很长一段时间,但这似乎很麻烦。

但我在想是否可以只启用 proguard 来删除程序不使用的类,我有一个简单的游戏,重量接近 25mb,我什至没有 2mb 的资产,我不在乎混淆。

这应该更容易实现吧?因为启用 proguard 时的大多数错误都是由于混淆引起的?

我可以这样做吗?怎么样?

谢谢

编辑:

我用 eclipse

build.gradle 文件:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "test"
        gdxVersion = '1.9.5'
        roboVMVersion = '2.3.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'

        admobVersion = '10.2.1';
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"

        compile "com.google.android.gms:play-services-ads:$admobVersion"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile fileTree(dir: 'libs', include: '*.jar')
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

【问题讨论】:

  • proguard 主要用于混淆,但如果你考虑它的大小,它只会减少 2-3 mb。 2 mb 的资产如何 25 mb。我有 10 mb 的 .apk 和 7.5 mb 的资产。
  • @AbhishekAryan 我不知道,我猜 google play service lib 添加了 7mb 之类的东西,我只将它用于 admob 广告
  • 我也在使用 com.google.android.gms:play-services-ads:10.0.1 的 google play 服务的 ads 子模块,但 libGDX 项目仍然需要 25 mb。
  • @AbhishekAryan 好的,所以我现在仔细检查了,当我从 Google Play 下载应用程序时,它显示 5.96 mb,安装在应用程序信息中时显示 15.96mb,我 90% 确定我已经看到它是 25mb,所以这将是数据节省,但仍然是 15.96mb 和 1.76mb 的资产
  • @AbhishekAryan sub module of google play service 是什么意思我只是把整个库扔在那里,对不起,如果我听起来很愚蠢,英语不是我的第一语言

标签: libgdx proguard


【解决方案1】:

在 android app 模块中添加这个。具有预构建 proguard-project.txt 文件的应用程序模块,该文件具有适用于您的 libgdx 项目的 proguard 规则。

buildTypes {
        release {
            minifyEnabled true   
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
            proguardFile 'proguard-project.txt'
        }
    }

在 project.properties 文件中取消提交这一行。

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

希望你没有使用皮肤,有时皮肤会产生问题,因为对象是从 .json 中获取的。

【讨论】:

  • 我用的是Skin,你能补充一下如何添加sub module of google play service而不是所有的lib吗?
  • 告诉我你使用的是什么模块的 google play services ?
  • 我如何检查这个?在哪里?
  • 好吧,我认为 proguard 将消除所有不必要的 google play 服务类,对吧?所以只添加我使用的谷歌播放服务模块是没有意义的
  • 你在使用 google play 服务什么,比如你在使用广告、google 游戏服务或其他东西
猜你喜欢
  • 1970-01-01
  • 2017-12-22
  • 2020-09-06
  • 2016-12-30
  • 2014-05-17
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 2016-06-26
相关资源
最近更新 更多