Android Studio – Add As Library Error – IncorrectOperationException: Must not change document outside command or undo-transparent action.

今天嘗試Android Studio上加入 Windows Azure Mobile ServicesSDK
當我嘗試把這個SDK加入成為LibraryAdd As Library“時出現了以下的錯誤…
又是和之前的問題一樣..把Android Studio 升級到 0.5.1便出現很多問題了..
IncorrectOperationException: Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor: Must not change document outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor

做了一會research 之後找到了解決方法..

解決方法
我們可以自行在build.gradle上加入以下 compile files(“path/filename.jar”)的參考便可以了
E.G. 我的Windows Azure Mobile Services SDK Library 的位置是在這裡的 “libs\mobileservices-1.1.0.jar
Windows Azure Mobile Services Path on Android Studio
所以在build.gradle上我的設定便會是這樣

compile files('libs/mobileservices-1.1.0.jar')

Android Studio - build.gradle - Windows Azure Mobile Services SDK
加入了參考後便可以使用 Windows Azure Mobile Services SDK for Android
E.g.
Activity 上我可以加入以下的參考 com.microsoft.windowsazure.mobileservices

import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.MobileServiceTable;
import com.microsoft.windowsazure.mobileservices.NextServiceFilterCallback;
import com.microsoft.windowsazure.mobileservices.ServiceFilter;
import com.microsoft.windowsazure.mobileservices.ServiceFilterRequest;
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponse;
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponseCallback;
import com.microsoft.windowsazure.mobileservices.TableOperationCallback;
import com.microsoft.windowsazure.mobileservices.TableQueryCallback;

Hope you find it useful

Leave a Reply