Home | History | Annotate | Download | only in examples
      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  */
     13 @KeepApplication
     14 public class NativeCallBack
     15 {
     16     /**
     17      * Suppose this is a native method that computes an answer.
     18      *
     19      * The -keep option regular ProGuard configuration will make sure it is
     20      * not renamed when processing this code.
     21      */
     22     public native int computeAnswer();
     23 
     24 
     25     /**
     26      * Suppose this method is called back from the above native method.
     27      *
     28      * ProGuard would remove it, because it is not referenced from java.
     29      * The annotation will make sure it is preserved anyhow.
     30      */
     31     @Keep
     32     public int getAnswer()
     33     {
     34         return 42;
     35     }
     36 
     37 
     38     public static void main(String[] args)
     39     {
     40         int answer = new NativeCallBack().computeAnswer();
     41 
     42         System.out.println("The answer is " + answer);
     43     }
     44 }
     45