在android studio 1.3中,我无法运行整个测试用例。我可以毫无问题地运行单个测试用例,但是当我尝试运行所有测试时,我得到以下错误:
var s:Shape = new Shape();
s.graphics.beginFill(0);
s.graphics.drawCircle(mc1.x + (mc1.width * .5), mc1.y + (mc1.height * .5), mc1.width / 2);
addChild(s);
mc1.mask = s;
我试图从shell和android studio增加我的记忆,但它根本没有帮助。
function doStuff(event:MouseEvent){
//only continue if pixel under the mosue is NOT transparent
//first, you need a bitmap to work with
//if you know for sure the position of your bitmap, you can do something like this:
var bm:Bitmap = mc1.getChildAt(0) as Bitmap;
//annoyingly though, FlashPro makes timeline bitmaps shapes,
//so the above won't work UNLESS you take your bitmap in the FlashPro Library
//and export it for actionscript, giving it a class name, then it will be an actual bitmap on the timeline.
//As an alternative, you could (very CPU expensively) draw the whole button as a bitmap
var bmd:BitmapData = new BitmapData(mc1.width,mc1.height,true,0x00000000);
bmd.draw(mc1);
var bm:Bitmap = new Bitmap(bmd);
//we get the 32bit pixel under the mouse point
var pixel:uint = bm.bitmapData.getPixel32(bm.x + event.localX,bm.y + event.localY);
//then we grab just the Alpha part of that pixel ( >> 24 & 0xFF ).
//if the value is 0, it's totally transparent, if it's 255, it's totally opaque.
//for this example, let's say anything greater than 0 is considered good to be a click
if((pixel >> 24 & 0xFF) > 0){
mc2.gotoAndStop(2);
}
}
我的测试都被模拟了(我有一种叫做模拟的味道)所以我切换到构建变体mockDebug然后我在终端上运行以下命令:
Exception: java.lang.OutOfMemoryError thrown from the
UncaughtExceptionHandler in thread "Test worker" java.lang.OutOfMemoryError: PermGen space
我的测试是使用robolectric作为测试运行器。
另一个有趣的事情是,如果我从项目资源管理器中取出并右键单击包含测试的包,并在包中运行测试..."然后它运行测试。所以我唯一的问题是让它从命令行运行。
答案 0 :(得分:0)
要解决此内存不足异常,我通过设置shell环境变量添加了更多内存,如下所示:
export JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=768m"
export JAVA_TOOL_OPTIONS="-Xmx1024m -XX:MaxPermSize=512m -Xms512m"
即使我在gradle.properties中设置了内存,但从命令行看起来却看不到那些属性。因此必须设置命令行java选项以增加内存。如果您在执行此操作后检查终端日志,您将看到这样的一行证明相同:
Picked up JAVA_TOOL_OPTIONS: -Xmx1024m -XX:MaxPermSize=512m -Xms512m