Android 打包时 Keep 住某些方法或类
# ${android_sdk}/tools/proguard/proguard-android.txt
# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
// android/support/annotation/Keep.java
/**
* Denotes that the annotated element should not be removed when
* the code is minified at build time. This is typically used
* on methods and classes that are accessed only via reflection
* so a compiler may think that the code is unused.
* <p>
* Example:
* <pre><code>
* @Keep
* public void foo() {
* ...
* }
* </code></pre>
*/
@Retention(CLASS)
@Target({PACKAGE,TYPE,ANNOTATION_TYPE,CONSTRUCTOR,METHOD,FIELD})
public @interface Keep {
}
// https://www.guardsquare.com/en/products/proguard/manual/usage
File filters
Like general filters, a file filter is a comma-separated list of file names that can contain wildcards. Only files with matching file names are read (in the case of input jars), or written (in the case of output jars). The following wildcards are supported:
? | matches any single character in a file name. |
---|---|
***** | matches any part of a filename not containing the directory separator. |
** | matches any part of a filename, possibly containing any number of directory separators. |
For example, "java/**.class,javax/**.class
" matches all class files in the java
and javax
.
Furthermore, a file name can be preceded by an exclamation mark '!' to exclude the file name from further attempts to match with subsequent file names.
For example, "!**.gif,images/**
" matches all files in the images
directory, except gif files.
Class specifications
A class specification is a template of classes and class members (fields and methods). It is used in the various -keep
options and in the -assumenosideeffects
option. The corresponding option is only applied to classes and class members that match the template.
The template was designed to look very Java-like, with some extensions for wildcards. To get a feel for the syntax, you should probably look at the examples, but this is an attempt at a complete formal definition:
[@annotationtype] [[!]public|final|abstract|@ ...] [!]interface|class|enum classname
[extends|implements [@annotationtype] classname]
[{
[@annotationtype] [[!]public|private|protected|static|volatile|transient ...] <fields> |
(fieldtype fieldname);
[@annotationtype] [[!]public|private|protected|static|synchronized|native|abstract|strictfp ...] <methods> |
<init>(argumenttype,...) |
classname(argumenttype,...) |
(returntype methodname(argumenttype,...));
[@annotationtype] [[!]public|private|protected|static ... ] *;
...
}]
Square brackets "[ ]" mean that their contents are optional. Ellipsis dots "..." mean that any number of the preceding items may be specified. A vertical bar "|" delimits two alternatives. Non-bold parentheses "()" just group parts of the specification that belong together. The indentation tries to clarify the intended meaning, but white-space is irrelevant in actual configuration files.
The
class
keyword refers to any interface or class. Theinterface
keyword restricts matches to interface classes. Theenum
keyword restricts matches to enumeration classes. Preceding theinterface
orenum
keywords by a!
restricts matches to classes that are not interfaces or enumerations, respectively.Every classname must be fully qualified, e.g. java.lang.String.Inner classes are separated by a dollar sign "$", e.g.
java.lang.Thread$State
. Class names may be specified as regular expressions containing the following wildcards:
? matches any single character in a class name, but not the package separator. For example, " com.example.Test?
" matches "com.example.Test1
" and "com.example.Test2
", but not "com.example.Test12
".***** matches any part of a class name not containing the package separator. For example, " com.example.*Test*
" matches "com.example.Test
" and "com.example.YourTestApplication
", but not "com.example.mysubpackage.MyTest
". Or, more generally, "com.example.*
" matches all classes in "com.example
", but not in its subpackages.** matches any part of a class name, possibly containing any number of package separators. For example, " **.Test
" matches allTest
classes in all packages except the root package. Or, "com.example.**
" matches all classes in "com.example
" and in its subpackages.matches the n'th matched wildcard in the same option. For example, " com.example.*Foo<1>
" matches "com.example.BarFooBar
".For additional flexibility, class names can actually be comma-separated lists of class names, with optional ! negators, just like file name filters. This notation doesn't look very Java-like, so it should be used with moderation.
For convenience and for backward compatibility, the class name * refers to any class, irrespective of its package.
Android 打包时 Keep 住某些方法或类的更多相关文章
- Java编译时根据调用该方法的类或对象所属的类决定
class Base{ int x = 1; static int y = 2; } class Subclass extends Base{ int x = 4; i ...
- 4.Android 打包时出现的Android Export aborted because fatal error were founds [closed]
Android 程序开发完成后,如果要发布到互联网上供别人使用,就需要将自己的程序打包成Android 安装包文件(Android Package,APK),其扩展名为.apk.使用run as 也能 ...
- Android自定义属性时TypedArray的使用方法
有时候android传统的页面布局不足以满足我们的需求,常常需要自己定义view,通常继承View,然后重写构造方法以及onDraw等函数,再 具体实现自己定义的复杂view.我们知道在给控件赋属性时 ...
- 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用
今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...
- Android studio运行时报错,方法,类找不到,或者JVM内存溢出解决方案
Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessExceptio ...
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
原文地址:http://blog.csdn.net/u_xtian/article/details/7495023 这个看似简单的问题困扰了我好久了,我已经google了很多相关的信息了,但是在我看来 ...
- Android退出时关闭所有Activity的方法
Android退出时,有的Activity可能没有被关闭.为了在Android退出时关闭所有的Activity,设计了以下的类: //关闭Activity的类 public class CloseAc ...
- Android Studio 打包时 Signature Version 选择V1还是V2 ?
只勾选V2会导致 7.0 以下的安卓机出现 INSTALL_PARSE_FAILED_NO_CERTIFICATES 的问题 ,推荐全选. 解决方案一v1和v2的签名使用1)只勾选v1签名并不会影响什 ...
- 退出Android程序时清除所有activity的实现方法
思路: 1. 自定义ActivityList管理类,添加删除维护该list; 2.Activity Stack 类似上面: 3.singleTask定义一个Activity为该启动模式,然后当返回时, ...
随机推荐
- 微信小程序社区爬取
# CrawlSpider 需要使用:规则提取器 和 解析器 # 1. allow设置规则的方法:要能够限制在目标url上面, 不要跟其他的url产生相同的正则即可 # 2. 什么情况下使用follo ...
- 解决thinkphp在开发环境下文件模块找不到的问题
win10系统下,phpstudy开发环境下小问题描述: 找不到public公共模块. Not Found The requested URL /public/admin/login.html was ...
- 寻觅Azure上的Athena和BigQuery (二):神奇的PolyBase
前情回顾 在“数据湖”概念与理论逐渐深入人心的今天,面向云存储的交互式查询这个需求场景显得愈发重要.这是因为原生的云存储(主要指S3这样的对象存储)既能够容纳大容量的明细数据,又能在性能和成本间取得一 ...
- kuangbin专题 专题一 简单搜索 Fire! UVA - 11624
题目链接:https://vjudge.net/problem/UVA-11624 题意:一个迷宫,可能有一个或者多个地方着火了,每过1个时间消耗,火会向四周蔓延,问Joe能不能逃出迷宫,只要走出迷宫 ...
- Markdown下,上传图片问题
最简单的方法: 1,登录qq 2,登录博客园,并打开博客园添加随笔的地方:如图: 3,选择需要截屏的地方,按住ctrl+alt+A截屏,然后在qq的发送栏内贴过去 4,鼠标左键按住不松开,然后拖到这里 ...
- Java设计模式学习笔记(四) 抽象工厂模式
前言 本篇是设计模式学习笔记的其中一篇文章,如对其他模式有兴趣,可从该地址查找设计模式学习笔记汇总地址 1. 抽象工厂模式概述 工厂方法模式通过引入工厂等级结构,解决了简单工厂模式中工厂类职责太重的问 ...
- BZOJ 2039人员雇佣
这道题教会我们一个道理靠谁也不如靠自己. 当时学长已经讲了,然而一脸懵逼,好吧,上网搜题解,二脸懵逼,于是自己动手,丰衣足食.自己推! 首先就是建模了,这道题谁与谁之间建模已经十分明了,超级源点,超级 ...
- 第三章.定制专属的kali
1.更新升级 • apt-get update • apt-get upgrade • apt-get dis-upgrade 2.根据个人喜好需求安装软件包 • 库 • Apt-get命令 • ...
- Maven(二)Maven 的基本配置
Maven 的基本配置 Maven 中仓库的概念 Maven 中的仓库是用拿过来存储所有项目的依赖关系的.当你创建一个 Maven 项目时,Maven 会通过依赖机制先到你本地仓库(自己维护的仓库)中 ...
- Asp.Net Core SwaggerUI 接入
Asp.Net Core SwaggerUI 接入 简单了解 swagger的目的简单来说就是,不用为每个接口手动写接口文档,因为它是根据接口自动生成的,接口更改时文档也同步更新,减少了手动更新的麻烦 ...