2013年1月12日土曜日

android memory

メモリを見ると100Mとか200Mとか余っててもバカスカ落ちる端末がいます。

この場合、アプリが100MBとか、そういう責任ではないのです。

 

androidのアプリにheapと言うのがあるようで

下は24MBで上が70MBですが、

この値を超えると強制終了するようです。

 

つまり、カンタンに言うと、自分の端末のスペックがいい人は、このheap問題に気づかないと言う事です。

galaxy sは記載されてないですが、結構heapサイズがでかいみたいで、検証の時には問題なかったのにHTCで急に落ちる事が何が問題かわかりませんでした。

 

以前の端末では16MBくらいだったらしいので、バージョンを1.6くらいからに設定したい人には、その値を目安にする方がいいかもしれません。

 

マニフェストのapplicationにandroid:largeHeap="true"と書くとheapのサイズが128MBになるみたいですが、android3.1とかからの技のようで、現段階(2012年5月)ではちょっと使えない技になります。※9割以上が2.1~2.3

 

バグを残さず制作するにはheapが、「24MB」の端末が必要です。

と言う事になります。最新の注意を払っても、出る時には出るout of errorです。

 

これでも16MBの端末があればエラーが出ますが。。

 

で、この部分に関しては、「エラーは出るものである。」

と言う結論をつけたいです。out of memory根絶は、よほど潤沢な検証環境がないかぎり厳しいです。

ユーザーの「落ちました。最悪です。」と言うコメントを享受しましょう。

 

で、出てしまった場合です。ここでは、メモリリークはないものとします。純粋にメモリの使用量が大きなページの場合

androidにユーザーのエラーのレポートが来るので、エラーの発生箇所の特定をしたら、

その部分や周辺にSystem.gc();を仕込みます。

メモリリークしてないのであれば、使ってる最中から、片付けをしていく感じにはなりますが、

これで、ある程度は改善できるかと思います。

または、使っている画像サイズを小さくしたり、bitmapの読み込み設定をしたり。


2013年1月11日金曜日

Windows RT Jailbreak Tool Released

"Earlier this week, reports surfaced that the Windows RT operating system had been jailbroken to allow for the execution of unsigned ARM desktop applications. Microsoft quickly issued a statementsaying it does not consider the findings to be part of a security vulnerability, and applauded the hacker for his ingenuity. Now, aWindows RT jailbreak tool has been released."

2013年1月10日木曜日

Why Trigger.io doesn’t use PhoneGap ? 5x faster native bridge

 
 
Firstly, our own native bridging technology is significantly faster – up to 5x on Android according to our testing below.
We wanted to design the best experience for web developers to create native mobile apps by having:
·       a super fast build-test cycle
·       no need to write any native code,
·       no need to setup your environment for local compiles,
·       no need to setup XCode and Eclipse
These design constraints mean that our approach includes a ton of small differences from PhoneGap, not just in our native bridge but in the code around it to provide the best possible API and best possible build process for developers coming from web technologies.
We're not averse to using existing solutions, and working to promote them and improve on them, where it's right for our customers (our Catalyst debugging tool is a hosted build ofWeinre). PhoneGap is a great product with lots of flexibility to write your own platform-specific native code in conjunction with HTML5 (which is not something Trigger.io offers).Strobe and appMobi both decided to use PhoneGap rather than developing their own native bridge.
Performance
Speed is a big concern for developers considering HTML5 and hybrid frameworks as opposed to native. So how does Trigger.io's native bridge perform in practice?
On iOS, compared with PhoneGap we saw that our bridge performed at a similar level to PhoneGap with a small increase in speed:
Performance results on iOS
On Android it's dramatically faster:
Performance results on Android
To test both native bridges we created a PhoneGap plugin for both Android and iOS which immediately responds to any call with the data sent to it. This allowed us to send varying amounts of data from JavaScript to native and back again. We also added an equivalent method to our own API. Adding a new method which does no processing means we can more accurately test the bridge itself rather than a particular API method. If you want to see the source code used for this benchmark you can find it on github.
How Trigger's native bridge technology works
Since launch, we've been asked about how our bridge technology works. Our architectural approach has much in common with PhoneGap's – but with some differences that reflect our different priorities and ways of thinking.
Here's how it works.
Wrapping and bridging to native
Our native bridge is what allows your JavaScript code to communicate with native code, in a way that's consistent across platforms. For mobile platforms, your code is outputted into a WebView / UIWebView mobile browser frame, and our wrapper grabs your API calls and 'translates' them as appropriate for each platform on the fly.
We deal with iOS and Android  in different ways:
iOS: JavaScript to Objective-C, and back again
To talk to native code from JavaScript, we take your API call, serialise and store it temporarily in the DOM. We then make a request to a fake URI (forge://…) which we intercept in native code – allowing us to read in and act upon the API call stored in the DOM.
To communicate from native to JavaScript, it's no problem: iOS gives us an API called
UIWebView.stringByEvaluatingJavaScriptFromString
which lets us execute JavaScript directly in the context of the UIWebView.
PhoneGap use a similar method, which explains why our performance is comparable in the benchmarking we did.
Android: Java to JavaScript, and back again
Java on Android provides an interface for Javascript to access Java methods directly, the opposite way round to what can be done in Objective-C. We use this method to pass API calls from Javascript back to native code – PhoneGap used to use this method but now avoid it. Instead PhoneGap use Javascript prompt boxes which they intercept in Java and prevent the user from seeing. This approach is heavier and hackier, but a decision they made in order to sideline a bug in the Android 2.3 simulation. It's not a bug that affects actual Android 2.3 devices, so we take this to be a bit of overkill.
For Java to Javascript communication we can cause Javascript methods to be called (but not get access to any data they return) using the following code:
WebView.loadUrl("javascript:alert('Hello World');")
Using this we can tell Javascript that there are responses waiting to be returned from Java and use the more efficient Javascript to Java interface to transfer the data. An issue with the loadUrl technique is by default it will close the keyboard if the user is currently entering text – something which is very annoying if you happen to make an API call in the background. We managed to work around this issue by preventing Android from closing the keyboard while an API call is made. PhoneGap instead run a local HTTP server on the device in Java, and send JavaScript requests to that server. We find that approach too heavyweight, especially as on devices with a proxy configured it has to resort to polling every 50ms, a very inefficient method.
In practice: calling native functionality from JavaScript with Trigger
How does this look in practice? You don't need to worry about what the bridge does – you simply call native functionality in through our Forge API (the full details of which are in our documentation).
Here's what happens when you run a command to access the native camera:
Native bridge flow
Conclusion
We aim to keep our framework as lean as possible and making the development environment and build process simple. We want the start to finish of cross-platform app development to be as straightforward as standard web development.
As a result we opted to build our own, faster bridge to native, for more responsive apps and fast development.
 
 
 

2013年1月9日水曜日

インストール可能な端末を限定する

はじめに
Android プラットフォーム を搭載している製品は実に様々です。スマホからタブレット、はたまたテレビまであります。画面サイズ・画面密度もバラバラで、ガラケーライクなテンキーが付いている機種もあったりします。またバージョンアップも頻繁にあります。 すべての端末で動作することがもちろんベストですが、アプリによってはインストール可能な端末の絞込みが必要になってきます。
そこで今回は インストール可能な端末を限定するための設定方法 を見ていきたいと思います。
AndroidManifest.xml で設定する
AndroidManifest.xml では「アプリが必要としている機能やスペックを持つ端末」を設定することができます。設定項目がいくつかあるので、それぞれ見ていきましょう。
APIレベル(SDKバージョン)
APIレベルは Android プラットフォームのバージョンのことです。SDKバージョンとも呼ばれます。Androidアプリでは、AndroidManifest.xml に インストールできる最小のAPIレベル( android:minSdkVersion )を uses-sdk で指定しなければいけないというルールがあります。ここで指定した最小のAPIレベル以下の端末ではアプリをインストールできません。また、主な対象とするAPIレベル( android:targetSdkVersion )も指定することができます。
例 (Android 2.2 から Android 2.3.3 まで)
1
2
3
4
<uses-sdk
    android:minSdkVersion="8"
    android:maxSdkVersion="10"
    android:targetSdkVersion="8" />
画面サイズと画面密度の種類
Android端末は画面サイズの大きさ、また画面密度によって大きくグループ化されています。<supports-screens> によってどの種類の画面サイズ・画面密度の端末でインストールできるか、または除外するか指定することができます。 まず画面サイズの種類を見てみましょう。
small 426dp x 320dp (mdpiで 426px x 320px) が最小
normal 470dp x 320dp (mdpiで 470px x 320px) が最小
large 640dp x 480dp (mdpiで 640px x 480px) が最小
xlarge 960dp x 720dp (mdpiで 960px x 720px) が最小
このような定義で分類されています。dp は端末の画面密度によってピクセル値が変わるので、 dp = px ではないことに注意してください。この種類によって、インストール可能な端末を限定することができます。例えば以下のように指定します。
例 (タブレットなどを除外する場合)
1
2
3
4
5
<supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="false"
    android:xlargeScreens="false" />
ハードウェア
特定のハードウェアが搭載されている端末に限定する場合は、 <uses-configuration> を使います。「ハードウェアキーボードが搭載されている端末」や「トラックボールが搭載されている端末」といったような条件で絞込みが可能です。
例 (QWERTYキーボードが搭載されている端末のみ)
1
2
3
<uses-configuration
    android:reqKeyboardType="qwerty"
    />
端末仕様
端末の仕様による制限をかけるには <uses-feature> を使います。「オートフォーカス付きのカメラが搭載されている端末」や「GPSを搭載している端末」などといった条件で絞込みが可能です。
例 (オートフォーカス・フラッシュ機能付きカメラが搭載されている端末のみ)
1
2
3
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.flash"/>
ライブラリ
アプリに必要な共有ライブラリを指定することで、指定のライブラリが含まれていない端末のインストールを制限することができます。制限をかけるには <uses-library> を使います。「GoogleMapライブラリが含まれている端末」などといった条件で絞り込むことができます。この要素は <application> 内に指定します。
例 (GoogleMapライブラリを必要としているアプリ)
1
2
3
4
<application android:name="MyApplication" >
    <uses-library android:name="com.google.android.maps" />
    ...
</application>
GooglePlay Android Developer Console で設定する
特定の端末を除外する
GooglePlay Android Developer Console からは、アプリの編集画面で「特定の端末を除外する」ことができます。
まずはアプリの編集画面を開き、「公開設定のオプション」の一番下の欄を見ます。
この欄の上のほうには AndroidManifest.xml で設定した内容が反映されています。マニフェストファイルに記述した内容で正確に指定できているか確認するときに便利ですね。下部にある「端末を表示」というリンクをクリックすると、端末リストが表示され、特定の端末を除外することができます。
端末の画面サイズ・画面密度を調べる
最後に、端末の解像度や画面サイズを取得するコードを掲載しておきます。 AndroidManifest.xml で対象とするスペックを指定するときに活用しましょう。
画面サイズの種類を取得する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Configuration conf = getResources().getConfiguration();
int size = conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
switch (size) {
case Configuration.SCREENLAYOUT_SIZE_SMALL:
    Log.d("TAG", "ScreenLayout : small");
    break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
    Log.d("TAG", "ScreenLayout : normal");
    break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
    Log.d("TAG", "ScreenLayout : large");
    break;
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
    Log.d("TAG", "ScreenLayout : xlarge");
    break;
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED:
    Log.d("TAG", "ScreenLayout : undefined");
    break;
}
画面密度を取得する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.d("TAG", "Density : " + metrics.density);
Log.d("TAG", "ScaledDensity : " + metrics.scaledDensity);
Log.d("TAG", "DensityDpi : " + metrics.densityDpi);
Log.d("TAG", "XDpi : " + metrics.xdpi);
Log.d("TAG", "YDpi : " + metrics.ydpi);
Log.d("TAG", "WidthPixels : " + metrics.widthPixels);
Log.d("TAG", "HeightPixels : " + metrics.heightPixels);
switch (metrics.densityDpi) {
case DisplayMetrics.DENSITY_LOW:
    Log.d("TAG", "DensityName : ldpi");
    break;
case DisplayMetrics.DENSITY_MEDIUM:
    Log.d("TAG", "DensityName : mdpi");
    break;
case DisplayMetrics.DENSITY_HIGH:
    Log.d("TAG", "DensityName : hdpi");
    break;
case DisplayMetrics.DENSITY_XHIGH:
    Log.d("TAG", "DensityName : xhdpi");
    break;
case DisplayMetrics.DENSITY_XXHIGH:
    Log.d("TAG", "DensityName : xxhdpi");
    break;
case DisplayMetrics.DENSITY_TV:
    Log.d("TAG", "DensityName : tvdpi");
    break;
}
まとめ
アプリの仕様や機能によっては、インストールすべきではない端末が必ず存在します。 アプリが必要とする端末の機能・スペックを明確にし、対象となる端末以外で誤ってインストールされないようにしましょう。
参考
 
 

2013年1月8日火曜日

Game Engines for Android

With Google IO fast approaching and GDC just completed I thought it would be interesting to take a look at the game engines available for mobile devices, specifically for x86 based mobile devices. There are many game engine choices out there, all with a different set of features, pricing, maturity, etc. After conducting a search online, I found a wide variety of game engines that can be used for creating games for Android* based mobile devices. Some provide x86 support, while others can be ported to support x86 devices without too much effort. 

Here is the list of game engines I have come across; I have included some features and details about each engine and an example game on the Android Market if I could find one.

  • jPCT-AE- http://www.jpct.net/jpct-ae/
    • A java 3D engine optimized for Android.
    • Nice set of features including 3DS, OBJ and other file support, skeletal animations, shader support, texture compression, collision detection, various lighting modes, transparency, fog, and more.
    • An all java game engine that supports x86 Android devices.
    • Free for personal and commercial use.
    • Example: https://play.google.com/store/apps/details?id=mk.grami.max
  • Libgdx - http://code.google.com/p/libgdx/
    • Cross platform (Windows, Linux, OSX and Android) 2D/3D Android engine. Build, run and iterate on the PC before deploying to phone.
    • C++ and Java based engine that easily ports to x86.
    • Box2d physics, TMX tile map, shaders, 2D particle system, sprite support, camera apis, OBJ and MD5 model loaders.
    • Full source code available for free.
    • C++/Java based engine that with a few minor changes I was able to run on x86 Android devices.
    • https://market.android.com/details?id=com.tani.penguinattack
  • Papaya Social Game Engine - http://papayamobile.com/developer/engine



  • moai - http://getmoai.com/

    • A mobile platform for game developers
    • Lua scripting language based development engine that has integrated cloud services available.
    • Engine is open source and free to use, pay for cloud services.


  • Cuttlefish Engine - http://www.cuttlefishengine.com/

    • 2D cross platform (Windows Phone, Android, iPhone, Windows PC) game engine.
    • Create game in an editor using scripting language (C# variant).
    • Designer interface to build games, Tile support and Box2d physics engine.
    • License purchase required for the Designer, engine source available for free. Trial available.


  • Orx - http://orx-project.org/

    • 2d cross platform (iPhone, iPad, Mac, Windows, Linux, Andrdoi) game engine.
    • Camera APIs, animations, sound, sprite rendering and data driven for fast and easy prototyping and development.
    • Free open source.
    • C++ based engine that should easily port to x86 Android devices.
    • Example: https://market.android.com/details?id=lyde.sik.gravity

  • Unigine - http://unigine.com/products/unigine/

    • 3D cross platform (Windows, Linux, Max, PS3, iOS, Android)
    • Physics, scripting, etc. Unclear what features are supported for mobile.
    • Evaluation available to companies working on commercial projects. License purchase required.
    • C++ based engine that should easily port to x86 Android devices.
    • Example: http://www.demolicious-game.com/


  • Gideros Studio - http://www.giderosmobile.com/

    • 2D cross platform (iPhone iPad, Android) game engine.
    • Write Lua code in provided IDE, iterate on PC with simulator.
    • Features include Box2d physics engine, fonts, sprites, tile maps and sensor integration.
    • Free version includes Gideros Splash screen, licensed version removes it.
    • iPhone example: http://itunes.apple.com/app/tim-the-timber/id417301495?mt=8


  • Candroidengine - http://code.google.com/p/candroidengine/

    • 2D Java engine.
    • Sprites, tile animation, background APIs, etc.
    • Dalvik only engine that should work on all architectures.
    • Full source code available for free.


  • Mages Engine - http://code.google.com/p/mages/

    • multiplayer client/server game engine
    • Java engine that should work on all architectures.
    • Full source code available for free.


  • Unreal Development kit - http://udk.com/

    • Android support coming at a future date.

  • Rokon - http://code.google.com/p/rokon/

    • 2D engine indicates it will soon start up again as Rokon 3 and will be built upon libgdx.


The great thing about Android on x86 is that it opens a new class of devices for all of the games built on these engines. Unfortunately not all these game engines have support for x86 native binaries but it's probably just a matter of time. x86 support is available in the latest Android NDK. Porting to x86 for some of these engines may simply be a recompile. We have created a couple of documents to guide you and have forums available to help along the way.


I hope this list helps those thinking about writing an Android game by providing some details of the choices available. Ideally I will try to update this article with the latest information as it develops, but please feel free to post comments about game engines I did not come across or any updated information you find.

Windows RT jailbroken to run third-party Desktop apps

It was only a matter of time: Windows RT has been hacked to allow non-Microsoft applications to run in Desktop. Prior to this hack, your Windows RT tablet (such as the Surface RT) could only run Metro apps, a special, touch-oriented version of Office… and that's it. Now, in theory, you can run any Desktop app on Windows RT
The hack, performed by Clokr, exploits a vulnerability in the Windows kernel that has existed for a long time — since before Microsoft ported Windows from x86 to ARM, in fact. Basically, the Windows kernel on your computer is configured to only execute files that meet a certain level of authentication. There are four levels: Unsigned (0), Authenticode (4), Microsoft (8), and Windows (12). On your x86 Windows system, the default setting is Unsigned — you can run anything you like. With Windows RT, the default, hard-coded setting is Microsoft (8); i.e. only apps signed by Microsoft, or parts of Windows itself, can be executed.
If you've ever wondered what some low-level exploit code looks like, now you know
Now, in theory, you could change this hard-coded setting– but all Windows RT devices use UEFI, and so Secure Boot detects the altered code and locks the system down.Secure Boot doesn't stop you from changing the setting in memory, however — and that's exactly what Clokr has done. By using some fairly simple (but ingenious) reverse engineering, Clokr discovered the location of this setting in memory — and then used Microsoft's remote debugger (usually used to debug Metro apps on a Surface RT) to execute some code that altered the value stored in memory. Voilà: A completely unlocked version of Windows RT that will run any Desktop app.
There are some complications, of course. First, you need to run the "jailbreak" every time you reboot (though it's not like you reboot a tablet very often). Second, you will need some developer tools to perform this jailbreak (but hopefully someone releases a standalone tool in the near future). Third, you are still limited to Desktop apps that have been compiled to ARM. It's easy to recompile an x86 program to ARM, but there currently aren't a lot of Desktop ARM apps in existence. You're not suddenly going to run Photoshop on your Surface RT, or Call of Duty. For the most part, you will be limited to apps that you compile yourself — but hey, over on XDA Developers, some users have already managed to get Putty and TightVNC working on Windows RT (pictured above).
It is a little bit ironic that Microsoft engineers slaved over Windows RT to make it a perfect port of x86 Windows, and yet the Microsoft bigwigs decided to artificially lock the operating system down. Again, the only thing preventing Windows RT from running third-party Desktop apps is that single digit setting; otherwise, Windows RT is a clean port of Windows 8.
… and not one of them is an official app
Ostensibly Windows RT is locked down for usability reasons — consumers really don't want a tablet that is unstable, has unreliable battery life, or is constantly under attack from malware — but Microsoft could've easily made the setting configurable. It just seems so arbitrary to prevent Windows RT users from ever installing Desktop apps, especially when the Windows Store is devoid of so many critical apps. There are thousands of apps (open-source or otherwise) that could be compiled to run on the Windows RT Desktop, and yet Microsoft doesn't want to hear it. It is understandable that Microsoft wants to keep the tablet experience "pure" — but then why include the Desktop at all?
I don't think we'll ever know why Microsoft disabled third-party Desktop apps on Windows RT — but now that it's been jailbroken, Microsoft has two options: Plug the hole, or embrace the change and roll out a fix that allows users to disable the setting in the Control Panel. Here's hoping for the latter.
 
 

Windows RT Jailbroken To Run Third-Party Desktop Apps

"We all knew it was just a matter of time, now it looks like Windows RT has been Jailbroken. From the article: 'The hack, performed by Clokr, exploits a vulnerability in the Windows kernel that has existed for a long time — since before Microsoft ported Windows from x86 to ARM, in fact. Basically, the Windows kernel on your computer is configured to only execute files that meet a certain level of authentication. There are four levels: Unsigned (0), Authenticode (4), Microsoft (8), and Windows (12). On your x86 Windows system, the default setting is Unsigned — you can run anything you like. With Windows RT, the default, hard-coded setting is Microsoft (8); i.e. only apps signed by Microsoft, or parts of Windows itself, can be executed.'"

Adobe、Creative Suite 2の「アクティベーション不要版」を公開

Adobe Systemsが「Photoshop」などクリエイティブ製品群の旧バージョン「Creative Suite 2」(CS2)に含まれるソフトウェアの「アクティベーション不要版」を同社サイトで公開している。昨年12月にCS2用のアクティベーションサーバを停止したための措置で、無料で取得できるAdobe IDさえあれば誰でもダウンロードできる状態になっている。

公開されたのは2005年に発売したPhotoshop、Illustrator、InDesign、GoLive、InCopyのCS2と、Acrobat Standard/Proの7.0、Acrobat Standard 8.0、Photoshop Elements 4.0/5.0、Premier Pro 2.0など。日本語版も用意されており、ダウンロードページに記載された専用シリアルナンバーを入力すればインストールして利用できる。

公開ページは一次アクセスが集中し接続しにくくなる事態となった。

なお、サポートOSはWindows 2000/XPおよびMac OS X版10.2.8〜10.3.8(PowerPC)と当時のまま。また、あくまで既存ユーザー向けの処置であり、ライセンスを持っていない人が利用すると当然ながらライセンス違反となる。