Exception java.lang.RuntimeException: java.lang.IllegalArgumentException: Optimized data directory /sdcard is not owned by the current user. Shared storage cannot protect your application from code injection attacks.

808 views
Skip to first unread message

VRS

unread,
Sep 5, 2013, 5:30:29 AM9/5/13
to moc...@googlegroups.com
Hello,

   I am trying to execute some JUnit Tests that use mockito with dexmaker in an Android Device, and in some devices I get this exception, and I don´t know exactly why. 

java.lang.RuntimeException: java.lang.IllegalArgumentException: Optimized data directory /sdcard is not owned by the current user. Shared storage cannot protect your application from code injection attacks.
at com.google.dexmaker.DexMaker.generateAndLoad(DexMaker.java:388)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:252)
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:56)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1216)
at mycountry.mypackage.MyTestClass.setUp(MyTestClass.java:80)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
Caused by: java.lang.IllegalArgumentException: Optimized data directory /sdcard is not owned by the current user. Shared storage cannot protect your application from code injection attacks.
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.loadDex(DexFile.java:149)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:261)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:229)
at dalvik.system.DexPathList.<init>(DexPathList.java:96)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:52)
at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:57)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at com.google.dexmaker.DexMaker.generateAndLoad(DexMaker.java:382)
... 16 more



Greetings

Haiqing Bu

unread,
Sep 6, 2013, 8:22:40 AM9/6/13
to moc...@googlegroups.com
could share some piece of your test code? 

在 2013年9月5日星期四UTC+8下午5时30分29秒,VRS写道:

VRS

unread,
Oct 9, 2013, 5:29:33 AM10/9/13
to moc...@googlegroups.com
Sure!

public class MyTest extends AndroidTestCase {

private Context context;

public MyTest() {
super();
}

@Override
public void setUp() throws Exception {
super.setUp();
// Some issues with dexmaker
System.setProperty("dexmaker.dexcache", "/sdcard");
Thread.currentThread().setContextClassLoader(
getClass().getClassLoader());

context = mock(Context.class, RETURNS_DEEP_STUBS); //this line cause the exception

}

//I have some test implemented but the error is in the setUp method

VRS

unread,
Oct 9, 2013, 5:38:41 AM10/9/13
to moc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages