1 import proguard.annotation.*; 2 3 /** 4 * This application illustrates the use of annotations for configuring ProGuard. 5 * 6 * You can compile it with: 7 * javac -classpath ../lib/annotations.jar NativeCallBack.java 8 * You can then process it with: 9 * java -jar ../../../lib/proguard.jar @ ../examples.pro 10 * 11 * The annotation will preserve the class and its main method, 12 * as a result of the specifications in lib/annotations.pro. 13 */ 14 @KeepApplication 15 public class NativeCallBack 16 { 17 /** 18 * Suppose this is a native method that computes an answer. 19 * 20 * The -keep option for native methods in the regular ProGuard 21 * configuration will make sure it is not removed or renamed when 22 * processing this code. 23 */ 24 public native int computeAnswer(); 25 26 27 /** 28 * Suppose this method is called back from the above native method. 29 * 30 * ProGuard would remove it, because it is not referenced from java. 31 * The annotation will make sure it is preserved anyhow. 32 */ 33 @Keep 34 public int getAnswer() 35 { 36 return 42; 37 } 38 39 40 /** 41 * The main entry point of the application. 42 * 43 * The @KeepApplication annotation of this class will make sure it is not 44 * removed or renamed when processing this code. 45 */ 46 public static void main(String[] args) 47 { 48 int answer = new NativeCallBack().computeAnswer(); 49 50 System.out.println("The answer is " + answer); 51 } 52 } 53