Building and using Skia for android

4,339 views
Skip to first unread message

efyx

unread,
Dec 5, 2011, 10:37:20 AM12/5/11
to skia-discuss
Hi,

i'am currently writting an application for android, and i wanted to
use skia inside JNI to draw onto a canvas.What I wanted to do, is to
build a static version of skia for android and link it to my code.

First i wanted to make sure this is possible? And then if my build of
skia will run on all android device? (at least arm device?)

Thanks.

Ryan Statzer

unread,
Dec 6, 2011, 2:18:14 AM12/6/11
to skia-d...@googlegroups.com
Yep. It's possible. Quite simple actually, though it's a bit tedious. I'm doing the same to get hardware accelerated drawing outside of Honeycomb and ICS.

Also it seems to work in my limited testing. I've tested it on my Gingerbread Moto Droid and Honeycomb Moto Xoom and haven't any problems.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/skia-discuss?hl=en.


efyx

unread,
Dec 6, 2011, 6:23:14 AM12/6/11
to skia-discuss
Hi,

thanks for your response. I was able to build skia for android (from
skia svn repository) but it seems that the build process doesn't
provide a libskia.a

How did you build a static version of libskia? I guess i can build it
from android source, but i don't want to build the whole android
source to get libskia.a.... Any advice?

Thanks a lot.

I guess i'am cleary doing something wrong, as the sample_app should
work without all the extra step i done? But i can't figure out how.

Derek

unread,
Dec 6, 2011, 8:11:39 AM12/6/11
to skia-d...@googlegroups.com
Check out http://code.google.com/p/skia/wiki/GettingStartedOnAndroid.  The skia team is working on supporting an NDK build and the initial set of instructions should be functional.  The big caveat is that that the android font rendering code in Skia's trunk only works on Android 4.0 as they updated the location of the system font files in that release.

~ Derek

efyx

unread,
Dec 6, 2011, 12:54:28 PM12/6/11
to skia-discuss
Hi Derek,

thanks for your response, however I target device prior to android
4.0.

I managed to build libskia.a for android by using skia revision 1236
(http://code.google.com/p/skia/source/detail?r=1236) with NDK r7
toolchain.

I wrote a sample app to draw onto a canvas with skia from JNI but
unfortunatly nothing is drawn. I have no crash and no error. Maybe I
am doing something wrong? I posted my java code and C code here :
http://pastie.org/private/lbh8w7421cuqoi1s0fcdyg and
http://pastie.org/private/sqnvllmirxbcgbtemyz8rw

The device I use for testing is using android 2.3.3

If you can have a look and let me know if you have any hint?

Thanks a lot.

On 6 déc, 14:11, Derek <djsol...@google.com> wrote:
> Check outhttp://code.google.com/p/skia/wiki/GettingStartedOnAndroid.  The

Derek Sollenberger

unread,
Dec 6, 2011, 1:47:23 PM12/6/11
to skia-d...@googlegroups.com
To get a binary that will work with previous releases (with the exception of text rendering) you will need to use the NDK to generate a toolchain that supports that API level.  The current toolchain API level is version 14 (4.0) but you can create a toolchain for API version 9 (2.3) which will work on your device. You must then update android/bin/android_setup.sh to use the new toolchain.  The NDK command will look something like this...

make-standalone-toolchain.sh --platform=android-9
~ Derek

efyx

unread,
Dec 9, 2011, 8:20:33 AM12/9/11
to skia-discuss
Hi Derek,

Thanks to your advice, i was able to compile skia using ndk standalone
toolchain. Now I trying to write a sample app that draw onto a canvas
but I can't figure out the right way to do this. I looked at the
sample app but the code is rather complex for me. Would you mind to
provide me a sample or some guidance to achieve this?

Thanks.

Elliot Poger

unread,
Dec 9, 2011, 9:00:36 AM12/9/11
to skia-d...@googlegroups.com, efy...@gmail.com
efyx-

You might want to check out the code in http://code.google.com/p/skia/source/browse/trunk/gm .  It may be easier to follow than sampleapp.

Derek Sollenberger

unread,
Dec 9, 2011, 9:22:07 AM12/9/11
to skia-d...@googlegroups.com
The Skia's Android sample app is using an Android OpenGL Surface to render into.  A simpler way of doing things is to render on the CPU using the NDK's ANativeWindow.  To do that you need to create a Surface object in Java so that you can attach it to your UI, then using native_window_jni.h in the NDK you can convert the Surface to an ANativeWindow.  Finally you can use the NDK to get access to the format/pixels of the ANativeWindow in order to construct an SkBitmap around that memory.  Once you have an SkBitmap you can attach it to an SkCanvas and draw into it. 

~ Derek

efyx

unread,
Dec 9, 2011, 10:37:49 AM12/9/11
to skia-discuss
Derek, that's exactly what i wanted to know! I'm going to try that and
let you know. Thanks a lot!

Elliot, nice tips about GM it contains a lot of information about skia
usage.

On 9 déc, 15:22, Derek Sollenberger <djsol...@google.com> wrote:
> The Skia's Android sample app is using an Android OpenGL Surface to render
> into.  A simpler way of doing things is to render on the CPU using the
> NDK's ANativeWindow.  To do that you need to create a Surface object in
> Java so that you can attach it to your UI, then using native_window_jni.h
> in the NDK you can convert the Surface to an ANativeWindow.  Finally you
> can use the NDK to get access to the format/pixels of the ANativeWindow in
> order to construct an SkBitmap around that memory.  Once you have an
> SkBitmap you can attach it to an SkCanvas and draw into it.
>
> ~ Derek
>
>
>
>
>
>
>
> On Fri, Dec 9, 2011 at 9:00 AM, Elliot Poger <epo...@google.com> wrote:
> > efyx-
>
> > You might want to check out the code in

> >http://code.google.com/p/skia/source/browse/trunk/gm.  It may be easier

efyx

unread,
Dec 10, 2011, 12:12:40 PM12/10/11
to skia-discuss
Hi Derek, so this was pretty straight forward. I got it running in
couple of hours! Thanks a lot for your time and your precious help!

I'll post my code later if someone is looking for doing something
similar.

On 9 déc, 15:22, Derek Sollenberger <djsol...@google.com> wrote:

> The Skia's Android sample app is using an Android OpenGL Surface to render
> into.  A simpler way of doing things is to render on the CPU using the
> NDK's ANativeWindow.  To do that you need to create a Surface object in
> Java so that you can attach it to your UI, then using native_window_jni.h
> in the NDK you can convert the Surface to an ANativeWindow.  Finally you
> can use the NDK to get access to the format/pixels of the ANativeWindow in
> order to construct an SkBitmap around that memory.  Once you have an
> SkBitmap you can attach it to an SkCanvas and draw into it.
>
> ~ Derek
>
>
>
>
>
>
>
> On Fri, Dec 9, 2011 at 9:00 AM, Elliot Poger <epo...@google.com> wrote:
> > efyx-
>
> > You might want to check out the code in

> >http://code.google.com/p/skia/source/browse/trunk/gm.  It may be easier

Daniel Wyatt

unread,
Jan 11, 2012, 6:39:25 PM1/11/12
to skia-d...@googlegroups.com
Mind sharing that code?
I'm interested in it. :)

kevin guan

unread,
Feb 9, 2012, 1:56:27 AM2/9/12
to skia-discuss


On 1月12日, 上午7时39分, Daniel Wyatt <daniel.wy...@gmail.com> wrote:
> Mind sharing that code?
> I'm interested in it. :)

I'm interested in it too. :)

Xingyun Lin

unread,
Feb 9, 2012, 11:37:59 PM2/9/12
to skia-d...@googlegroups.com
Hi efyx,

Could you share the code? Many thanks!

Trani Nicolas

unread,
Feb 10, 2012, 5:10:46 AM2/10/12
to skia-d...@googlegroups.com
Hi,

you can find a sample project here : http://efyx.io/android/TestSkia.zip it also contain a prebuild version of skia (revision 2839). In file Android.mk update path where your skia sources are and you can build the project, it should work.

I also put the code on pastie :
Cheers.

On Fri, Feb 10, 2012 at 5:37 AM, Xingyun Lin <linxi...@gmail.com> wrote:
Hi efyx,

Could you share the code? Many thanks!

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/wIwt9wDehI8J.

doublerye

unread,
Feb 18, 2012, 12:18:27 AM2/18/12
to skia-d...@googlegroups.com
I was able to run your sample app, however I am now trying to use the image decoder libraries and it looks like your libcore.so doesn't contain those libraries. Can you describe how you built the libcore.so? I am currently able to build Skia locally, however the make never generate a static library, they do however build a giant libSampleApp.so.

Thanks!

Bartek Teodorczyk

unread,
Apr 26, 2012, 6:41:53 AM4/26/12
to skia-d...@googlegroups.com
Hi,

Would be possible for you to provide detailed instruction how the libcore.so was built for revision 2839?

Thanks


On Friday, February 10, 2012 11:10:46 AM UTC+1, efyx wrote:
Hi,

you can find a sample project here : http://efyx.io/android/TestSkia.zip it also contain a prebuild version of skia (revision 2839). In file Android.mk update path where your skia sources are and you can build the project, it should work.

I also put the code on pastie :
Cheers.

On Fri, Feb 10, 2012 at 5:37 AM, Xingyun Lin <linxi...@gmail.com> wrote:
Hi efyx,

Could you share the code? Many thanks!

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/wIwt9wDehI8J.

To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss+unsubscribe@googlegroups.com.

at...@ntrack.com

unread,
May 10, 2012, 11:26:35 AM5/10/12
to skia-discuss
I would second Bartek request for detailed hints on how to build the
so :)

thanks!
athos

jiajun zhang

unread,
Sep 28, 2012, 10:47:14 AM9/28/12
to skia-d...@googlegroups.com
Hi,efyx
How did you get the libcore.a file can you tell me .I was build skia -r1236 can get libskia.a  but it doesn't work.The stack is:

undefined refrence SkCanvas:: .....

And there is a problem :How can I build the skia with ndk..

Thanks
jhondge

在 2012年2月10日星期五UTC+8下午6时10分46秒,efyx写道:

Athos Bacchiocchi

unread,
Sep 28, 2012, 11:01:57 AM9/28/12
to skia-d...@googlegroups.com
Il 28/09/2012 16:47, jiajun zhang ha scritto:
> Hi,efyx
> How did you get the libcore.a file can you tell me .I was build skia
> -r1236 can get libskia.a but it doesn't work.

here's some notes I am keeping to remember the various steps:
https://docs.google.com/document/pub?id=18pUi0s3sB7_kYtf9k-B4VP_uoGBX4rcGgs-F-DAm17E

it's a work in progress written for my own reference, so it may be
obscure in some points :)
A quicker way is to build the testbench app and grab "bench.so", using
it as a prebuilt shared module in your app.
You will carry with you unnecessary things but it contains everything
(eg: the gpu classes)

athos

jiajun zhang

unread,
Sep 28, 2012, 11:23:14 AM9/28/12
to skia-d...@googlegroups.com
Thanks a lot,athos bacchiocchi.I'll try it again.
Do you know how to use the ndk-r8 toolchain complie skia?
在 2012年9月28日星期五UTC+8下午11时02分00秒,athos bacchiocchi写道:

jiajun zhang

unread,
Sep 28, 2012, 11:22:23 PM9/28/12
to skia-d...@googlegroups.com
Thanks athos bacchiocchi
 I was try it .with your thead:https://docs.google.com/document/pub?id=18pUi0s3sB7_kYtf9k-B4VP_uoGBX4rcGgs-F-DAm17E
But there is a error:
./src/core/ft2build.h:56:38: fatal error: freetype/config/ftheader.h:

I'm so sad.the ftheader.h is exsits in /usr/include/freetype2 .

help me .could you share your files of  modified.
在 2012年9月28日星期五UTC+8下午11时02分00秒,athos bacchiocchi写道:

jiajun zhang

unread,
Sep 29, 2012, 1:55:17 AM9/29/12
to skia-d...@googlegroups.com
HI athos.
I was complete build liskia.a.But when i use it prebuilt on my own shared.
and this trace is:
/home/administrator/SKiaDemo/jni/skia_demo.cpp:22: undefined reference to `SkImageDecoder::DecodeFile(char const*, SkBitmap*, SkBitmap::Config, SkImageDecoder::Mode, SkImageDecoder::Format*)'

attachment is my android.mk and libskia.a
Please help me to resovled it!
Thanks.


在 2012年5月10日星期四UTC+8下午11时26分35秒,athos bacchiocchi写道:
Android.mk
libskia.a

athos bacchiocchi

unread,
Oct 4, 2012, 6:36:53 AM10/4/12
to skia-d...@googlegroups.com
be sure to have git installed, otherwise gclient won't be able to checkout external projects repositories (including freetype).

athos
Reply all
Reply to author
Forward
0 new messages