出發點:java
固然是因爲編程習慣太好,打了一堆中文log,其實只是想給測試看。然而若是包被反編譯,看log基本都能理解流程了,有點尷尬。因此此文主要探究proguard配置,以去除log。android
如下過程示例,來自於這段代碼。編程
public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private String a = "a"; private String b = "b"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG, "This is" + a + b); } }
啥都不配置的狀況下,反編譯的smali代碼以下:app
# virtual methods .method public onCreate(Landroid/os/Bundle;)V .locals 2 invoke-super {p0, p1}, Landroid/support/v7/app/c;->onCreate(Landroid/os/Bundle;)V const p1, 0x7f09001b invoke-virtual {p0, p1}, Lcom/rentee/logremove/MainActivity;->setContentView(I)V const-string p1, "MainActivity" new-instance v0, Ljava/lang/StringBuilder; const-string v1, "This is" invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V iget-object v1, p0, Lcom/rentee/logremove/MainActivity;->m:Ljava/lang/String; invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; iget-object v1, p0, Lcom/rentee/logremove/MainActivity;->n:Ljava/lang/String; invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; move-result-object v0 invoke-static {p1, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I return-void .end method
很明顯,整條字符串拼接過程是由StringBuilder完成的。ide