您的位置:首页 > 其它

proguard-project.txt文件,减少谷歌播放业务“的APK大小的影响

2015-11-13 14:43 465 查看
今天在做admob,由于Google service_lib 太大,引用进来,发现生成的apk实在是太大了,查资料,找到 一点

  资料名称:减少谷歌播放业务“的APK大小的影响

  连接地址:http://googleadsdeveloper.blogspot.in/2015/01/reducing-google-play-services-impact-on.html

 浏览条件:翻墙

里面的有方法。。。。。

遇到第一种方法:Split JAR
Architecture

Beginning with Google Play services 6.5, additional maven artifacts have been added to the Google Repository that contain single domains of functionality. This means that you can include just those portions of Google Play services that your app uses. For example,
here’s how to configure gradle to incorporate the JAR that contains functionality relating to ads:
dependencies {
compile 'com.google.android.gms:play-services-ads:6.5.+'
}


That line instructs gradle to include everything Mobile Ads developers need, with the exception of the IMA
SDK JAR needed for IMA applications.

Please note that if you currently initialize Mobile Ads SDK banner ads via XML layout files, you should continue including the full Google Play services artifact. See this
blog post for more information.
点进去看一下:发现是要:To prevent ProGuard from
stripping away required classes, add the following lines in the 
/proguard-project.txt
 file:

说一下:
proguard-project.txt
 file:

      关于使用还是很容易的,只要将eclipse项目中project.properties文件中的

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
前的注释#放开即可,然后右击项目-->Android Tools-->Export Signed/Unsigned Application Package。再慢慢下一步就可以了。

通常情况下,我们只需要作以上几步操作就能满足需求,如果有一些特殊要求,某些类或者jar包不需要混淆,这个时候就需要修改proguard-project.txt文件了。以下是网上搜索的网友分享的经验:

1.在proguard-project.txt文件中添加不需要混淆的类和第三方的jar包

 

 


这个是保持自己包中不需要混淆的类,如果有些类调用了jni也不需要混淆,不然会出错。还有如果项目中有其他项目作为library引入,那这些项目的一些类也不能混淆。

 



这个是保持项目中的第三方jar不混淆

 



另外加上上面几句话,不然会在控制台中报warning警告

2.另外还有其他一些经验:

-injars  androidtest.jar【jar包所在地址】 

-outjars  out【输出地址】

-libraryjars    'D:\android-sdk-windows\platforms\android-9\android.jar' 【引用的库的jar,用于解析injars所指定的jar类】

-optimizationpasses 5

-dontusemixedcaseclassnames 【混淆时不会产生形形色色的类名 】

-dontskipnonpubliclibraryclasses 【指定不去忽略非公共的库类。 】

-dontpreverify 【不预校验】

-verbose

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 【优化】

-keep public class * extends android.app.Activity  【不进行混淆保持原样】

-keep public class * extends android.app.Application

-keep public class * extends android.app.Service

-keep public class * extends android.content.BroadcastReceiver

-keep public class * extends android.content.ContentProvider

-keep public class * extends android.app.backup.BackupAgentHelper

-keep public class * extends android.preference.Preference

-keep public class com.android.vending.licensing.ILicensingService

-keep public abstract interface com.asqw.android.Listener{

public protected <methods>;  【所有方法不进行混淆】

}

-keep public class com.asqw.android{

public void Start(java.lang.String); 【对该方法不进行混淆】

}

-keepclasseswithmembernames class * { 【保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后)】

native <methods>;

}

-keepclasseswithmembers class * { 【保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。】

public <init>(android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembers class * {

public <init>(android.content.Context, android.util.AttributeSet, int);

}

-keepclassmembers class * extends android.app.Activity {【保护指定类的成员,如果此类受到保护他们会保护的更好 】

public void *(android.view.View);

}

-keepclassmembers enum * {

public static **[] values();

public static ** valueOf(java.lang.String);

}

-keep class * implements android.os.Parcelable {【保护指定的类文件和类的成员】

public static final android.os.Parcelable$Creator *;

}

3.http://www.apkbus.com/android-131995-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息