2017-10-20 117 views
3

我在Android庫上使用Proguard,但它似乎創建一個VerifyError在一個特定的類,同時縮小或混淆示例代碼。 (即使用-dontobfuscate-dontshrink將刪除該錯誤)。使用Proguard邏輯運算驗證錯誤

我可以通過一個簡單的例子(將命令./gradlew clean test重現錯誤)與進行隔離,但我並不真正瞭解真正的問題。

我失敗的測試將只嘗試實例化一個對象:

package a.b.c; 

public class FailingTest { 
    @org.junit.Test 
    public void name() throws Exception { 
    new D(); 
    } 
} 

和相關的類就是這麼簡單:

package a.b.c; 

public class D { 
    public void f(int g) { 
    if (g < 0) { 
     System.out.println("test"); 
    } 
    } 
} 

其實任何邏輯操作將引發一個錯誤(例如,只有在方法體內放置System.out.println(g == 2);也會失敗)。

Proguard的構造如下:

-keep public class a.b.c.D { 
    public protected *; 
} 

# With those options, the test will be successful. 
#-dontobfuscate 
#-dontshrink 

的堆棧跟蹤是如下:

java.lang.VerifyError: Expecting a stackmap frame at branch target 37 
Exception Details: 
    Location: 
    a/b/c/D.f(I)V @17: ifeq 
    Reason: 
    Expected stackmap frame at this location. 
    Bytecode: 
    0x0000000: bb00 0559 b700 0ab6 000b 4d2c b900 0c01 
    0x0000010: 0099 0014 2cb9 000d 0100 4eb2 0007 2db6 
    0x0000020: 0008 a7ff e9b1       

    at a.b.c.FailingTest.name(FailingTest.java:7) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114) 
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57) 
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66) 
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) 
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) 
    at com.sun.proxy.$Proxy3.processTestClass(Unknown Source) 
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) 
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377) 
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54) 
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

回答

0

2.3.3更新buildscript的依賴com.android.tools.build:gradle3.0.0gradle wrapper3.34.1似乎解決Progua rd的行爲。

我想這是嵌入在這個特定依賴項中的Proguard版本固有的錯誤。