In the following example, both "TestPrinter" and "Tester" are in same package
("com.example.test"). However MainActivity where the proxy generation happens
is under a different package ("com.example").
Executing the MainActivity throws an exception "java.lang.IllegalAccessError"
//TestPrinter.java
package com.example.test;
public class TestPrinter {
private static final String TAG = "TestPrinter";
//package visible method.
void method4(String arg1){
Log.i(TAG, String.format("Executing method4(%s)", arg1));
}
}
//Tester.java
package com.example.test;
public class Tester {
public void test(TestPrinter printer){
Random r = new Random();
printer.method4(UUID.randomUUID().toString());
}
}
//MainActivity.java
package com.example;
public class MainActivity extends Activity {
public static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.create_proxy).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
InvocationHandler handler = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] objects) throws Throwable {
Log.i(TAG,
String.format("%s.%s is being invoked with argument = %s",
proxy.getClass().getSimpleName(), method.getName(), objects));
Object result = ProxyBuilder.callSuper(proxy, method, objects);
return result;
}
};
TestPrinter printer =
ProxyBuilder.forClass(TestPrinter.class)
.dexCache(getApplicationContext().getDir("dex", Context.MODE_PRIVATE))
.handler(handler)
.build();
new Tester().test(printer);
} catch (Throwable e) {
Log.e(TAG, "Error creating runtime proxy", e);
}
}
});
}
}
Original issue reported on code.google.com by ajaykuma...@gmail.com on 1 May 2014 at 9:26
Original issue reported on code.google.com by
ajaykuma...@gmail.com
on 1 May 2014 at 9:26