Are the methods included in the final executable file defined?

When creating and deploying an executable file on Android without launching ProGuard, are the unreferenced methods included in the final executable file used?

Also unreferenced methods from external libraries are not included?

Is this behavior dependent on the Java compiler or does dex do all the trimming, if any?

+6
source share
1 answer

I tested a simple class (all of these methods were not found):

public class Test { private void privateMethod() { System.out.println("private"); } protected void protectedMethod() { System.out.println("protected"); } public void publicMethod() { System.out.println("public"); } void method() { System.out.println("method"); } } 

I compiled the APK, extracted Test.class and decompiled it (using javap -c ). I got the following results. I also tested using jar instead of APK, and the result was exactly the same. I used Java 1.6.0_29.

  protected void protectedMethod(); Code: 0: getstatic #44 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #47 // String protected 5: invokevirtual #46 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return public void publicMethod(); Code: 0: getstatic #44 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #48 // String public 5: invokevirtual #46 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return void method(); Code: 0: getstatic #44 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #49 // String method 5: invokevirtual #46 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return 

This means that only private functions are excluded during compilation.

I also tried to declare the class final , but the result was the same.

+5
source

Source: https://habr.com/ru/post/919331/


All Articles