2017-04-10 39 views
0

我一直想要啓用proguard很長一段時間,但它似乎很麻煩。Libgdx enable 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" 
} 
+0

proguard主要用於混淆,但如果考慮它的大小,它只會減少2-3 mb。 25Mb與2Mb資產。我擁有10 MB的資產,擁有7.5 MB的資產。 – Aryan

+0

@AbhishekAryan我不知道,我猜想谷歌播放服務lib添加像7mb和Im只使用它的admob廣告 – centenond

+0

我也使用'com.google.android.gms:play-services的谷歌播放服務的廣告子模塊-ads:10.0.1',但對於libGDX項目來說仍然是25 MB。 – Aryan

回答

1

添加這裏面的Android應用程序模塊。具有預編譯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獲取的對象。

+0

我正在使用皮膚,你可以添加如何添加谷歌播放服務的子模塊而不是所有的lib? – centenond

+0

告訴我你使用谷歌播放服務的模塊? – Aryan

+0

我該如何檢查?哪裏? – centenond