<div dir="ltr">Hi all,<div><br></div><div>     <span style="color:rgb(0,0,0)"> While instrumentation of android apps, if the injected class contains an interface, the instrumented apk cannot be installed in Android successfully, a dexopt error is reported.</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">    my instrumentation code is  shown below. It replaces the startActivity statement with a static function f() defined in class Instrument</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">   </span><font color="#000000">protected void internalTransform(final Body body, String s, Map&lt;String, String&gt; stringStringMap) {</font></div><div><font color="#000000">        </font></div><div><font color="#000000">        final PatchingChain units = body.getUnits();</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">        for (Iterator&lt;Unit&gt; iter = units.snapshotIterator(); iter.hasNext(); ) {</font></div><div><font color="#000000">            final Unit u = iter.next();</font></div><div><font color="#000000">            u.apply(new AbstractStmtSwitch() {</font></div><div><font color="#000000">                @Override</font></div><div><font color="#000000">                public void caseInvokeStmt(InvokeStmt stmt) {</font></div><div><font color="#000000">                    InvokeExpr invokeExpr = stmt.getInvokeExpr();</font></div><div><font color="#000000">                    if (invokeExpr instanceof InstanceInvokeExpr &amp;&amp;</font></div><div><font color="#000000">                            invokeExpr.getMethod().getName().equals(&quot;startActivity&quot;)) {</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">                        SootClass instrumentClass = Scene.v().getSootClass(&quot;Instrument&quot;);</font></div><div><font color="#000000">                        SootMethod instrumentMethod = instrumentClass.getMethodByName(&quot;f&quot;);</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">                        List&lt;Value&gt; args = new ArrayList&lt;Value&gt;();</font></div><div><font color="#000000">                        Unit insertStmt = Jimple.v().newInvokeStmt(</font></div><div><font color="#000000">                                Jimple.v().newStaticInvokeExpr(instrumentMethod.makeRef(),args)</font></div><div><font color="#000000">                        );</font></div><div><font color="#000000">                        units.insertBefore(insertStmt, stmt);</font></div><div><font color="#000000">                        units.remove(stmt);</font></div><div><font color="#000000">                        body.validate();</font></div><div><font color="#000000">                    }</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">                }</font></div><div><font color="#000000">            });</font></div><div><font color="#000000">        }</font></div><div><font color="#000000">    }</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">The Instrument.java is defined below:</font></div><div><br></div><div><font color="#000000"><div>import A;</div><div>public class Instrument {</div><div>    public static int f() {</div><div>        A a = A.Stub.asInterface();</div><div>        return a.f();</div><div>    }</div><div>}</div><div><br></div><div>and class A is defined as an interface </div><div><br></div><div><div>public interface A  {</div><div>    public int f();</div><div><br></div><div>    public static abstract class Stub implements A {</div><div>        public static A asInterface() {</div><div>            return new AImpl();</div><div>        }</div><div>    }</div><div>}</div><div><br></div><div>class AImpl implements A {</div><div><br></div><div>    @Override</div><div>    public int f() {</div><div>        return 0;</div><div>    }</div><div>}</div></div><div><br></div><div>Is the interface class output into the apk incorrectly?</div><div><br></div><div>Thanks a lot!</div><div><br></div><div>Zipeng Zhang</div><div><br></div><div><br></div><div><br></div></font></div><div><font color="#000000"><br></font></div></div>