How to build a skia shared object (.so) for android

1,956 views
Skip to first unread message

Manish Rawat

unread,
Jan 31, 2017, 6:57:12 AM1/31/17
to skia-discuss
Hi,

After following steps mentioned here https://skia.org/user/build, I was able to compile skia on a windows machine. However, currently it creates a static library (libskia.a). How can I create a shared library (.so)?

I executed following commands on command window.

gn gen out/Default --args="ndk=\"path-to-ndk" target_cpu=\"arm\""
..\ninja -C  out\Default

I would greatly appreciate any pointers/help here.

Thanks,
Manish

Hal Canary

unread,
Jan 31, 2017, 7:33:18 AM1/31/17
to skia-discuss
On Tue, Jan 31, 2017 at 6:57 AM, Manish Rawat <rawat0...@gmail.com> wrote:
After following steps mentioned here https://skia.org/user/build, I was able to compile skia on a windows machine. However, currently it creates a static library (libskia.a). How can I create a shared library (.so)?


Did you try:
 
gn gen out/Default --args='ndk="path-to-ndk" target_cpu="arm" is_component_build=true'

Manish Rawat

unread,
Feb 6, 2017, 6:24:44 AM2/6/17
to skia-discuss
Thanks for the reply.

Yes I have tried the above command, followed by
..\ninja -C  out/Default

It gives an error:
ninja: fatal: CreateProcess: The parameter is incorrect.


What could be the issue here? How can I get more information around this.

Also, using the command as is gives below error
ERROR at the command-line "--args":1:1: Invalid token.
'ndk=C:\Users\manishra\AppData\Local\Android\sdk\ndk-bundle" target_cpu=arm is_component_build=true'
^
Strings are delimited by " characters, not apostrophes.


However, I fixed the command by replacing apostrophes with "

PS: I am using a windows machine to compile.

Regards,
Manish

Mike Klein

unread,
Feb 6, 2017, 6:50:14 AM2/6/17
to skia-discuss
You might try moving the Android NDK to a shorter path like C:\ndk?  Windows has relatively short maximum command line and path lengths.  Sometimes they cause problems like this.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Hal Canary

unread,
Feb 6, 2017, 8:56:07 AM2/6/17
to skia-discuss
I use bash on windows.  Quotes are wierd in cmd shell.  Your mileage may vary.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Manish Rawat

unread,
Feb 7, 2017, 2:16:13 AM2/7/17
to skia-discuss
That didn't help. Below logs

C:\Users\manishra\Documents\skia\depot_tools\skia>gn gen out\Default --args="ndk=\"C:\\ndk\" target_cpu=\"arm\" is_component_build=true"
Done. Made 35 targets from 25 files in 99ms
C:\Users\manishra\Documents\skia\depot_tools\skia>..\ninja -C  out\Default
ninja: Entering directory `out\Default'

ninja: fatal: CreateProcess: The parameter is incorrect.

I will try to use bash on windows to see if that helps. 


Thanks,
Manish

Mike Klein

unread,
Feb 7, 2017, 8:36:49 AM2/7/17
to skia-discuss
You might try running `ninja -t commands -C out/...`.  That will print the commands Ninja runs.  Then you can see if you can run those commands directly yourself.  If you run `ninja -v -C out/...`, Ninja will print the commands it's running as it runs.  In fact, it ought to be printing them already when they fail... can you run whatever command is failing directly yourself?

Hal Canary

unread,
Feb 7, 2017, 9:20:48 AM2/7/17
to skia-discuss

Also show us the args.gn file in the output directory.

Manish Rawat

unread,
Feb 8, 2017, 1:56:57 AM2/8/17
to skia-discuss
`ninja -t commands -C out/Default` doesn't seem to work. It gives an error

ninja: error: loading 'build.ninja': The system cannot find the file specified.

However, I checked and the build.ninja file is present in depot_tools\skia\out\Default directory.

`ninja -v -C out/Default' works and prints below before failing. Not sure, what command failed here.

[1182/1185] C:\ndk/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -MMD -MF obj/third_party/externals/sfntly/cpp/src/sfntly/tools/subsetter/sfntly.subsetter.o.d -DSFNTLY_NO_EXCEPTION -I../../third_party/externals/sfntly/cpp/src -I../../third_party/externals/icu/source/common -w -fstrict-aliasing -fPIC -fvisibility=hidden -Werror -march=armv7-a -mfpu=neon -mthumb --sysroot=C:\ndk/platforms/android-18/arch-arm --target=arm-linux-androideabi -BC:\ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/arm-linux-androideabi/bin -Wno-unused-parameter -gline-tables-only -std=c++11 -fno-threadsafe-statics -fvisibility-inlines-hidden -isystemC:\ndk/sources/android/support/include -isystemC:\ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -isystemC:\ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -fno-exceptions -fno-rtti -c ../../third_party/externals/sfntly/cpp/src/sfntly/tools/subsetter/subsetter.cc -o obj/third_party/externals/sfntly/cpp/src/sfntly/tools/subsetter/sfntly.subsetter.o
[1183/1185] cmd.exe /c echo > obj/third_party/sfntly/sfntly.stamp
[1184/1185] cmd.exe /c echo > obj/pdf.stamp
ninja
: fatal: CreateProcess: The parameter is incorrect.

Also, below is the content of args.gn

ndk = "C:\ndk"
target_cpu
= "arm"
is_component_build
= true

PS: I was able to compile a .so using the same set of commands on an ubuntu machine. Not sure, what is going wrong on the windows machine.

Thanks,
Manish

Mike Klein

unread,
Feb 8, 2017, 9:29:36 AM2/8/17
to skia-discuss
I think if you cd into out/Default, `ninja -t commands` will work.  Or, invert the order of the arguments: `ninja -C out/Default -t commands`.

Please run the commands yourself so we know which one is failing?

You can also try running ninja with `-j 1` so that it runs one process at a time.  That should make it pretty clear which is the failure.

You can also try running ninja with `-k 0` so that it continues to run as much as possible even after an error occurs.  Running that a few times can help narrow down where the problem is.

Manish Rawat

unread,
Feb 9, 2017, 1:26:03 AM2/9/17
to skia-discuss
It looks like the last command is too large for the command prompt to handle. viz.
C:\ndk/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -shared --sysroot=C:\ndk/platforms/android-18/arch-arm --target=arm-linux-androideabi -BC:\ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/arm-linux-androideabi/bin -LC:/ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -LC:/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x obj/src/c/libskia.sk_paint.o obj/src/c/libskia.sk_surface.o obj/src/core/libskia.SkAAClip.o obj/src/core/libskia.SkAnnotation.o obj/src/core/libskia.SkAlphaRuns.o obj/src/core/libskia.SkATrace.o obj/src/core/libskia.SkAutoPixmapStorage.o obj/src/core/libskia.SkBBHFactory.o obj/src/core/libskia.SkBigPicture.o obj/src/core/libskia.SkBitmap.o obj/src/core/libskia.SkBitmapCache.o obj/src/core/libskia.SkBitmapController.o
...
obj
/third_party/externals/libwebp/src/utils/libwebp.color_cache.o obj/third_party/externals/libwebp/src/utils/libwebp.filters.o obj/third_party/externals/libwebp/src/utils/libwebp.huffman.o obj/third_party/externals/libwebp/src/utils/libwebp.huffman_encode.o obj/third_party/externals/libwebp/src/utils/libwebp.quant_levels.o obj/third_party/externals/libwebp/src/utils/libwebp.quant_levels_dec.o obj/third_party/externals/libwebp/src/utils/libwebp.random.o obj/third_party/externals/libwebp/src/utils/libwebp.rescaler.o obj/third_party/externals/libwebp/src/utils/libwebp.thread.o obj/third_party/externals/libwebp/src/utils/libwebp.utils.o  -lEGL -lGLESv2 -llog -lgnustl_static -ldl -Wl,-soname,libskia.so -o libskia.so


I tried to package only a few .o into the final .so by removing them from the above command and was able to create a .so.

I googled and found this:
On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

This limitation applies to the command line, individual environment variables (such as the PATH variable) that are inherited by other processes, and all environment variable expansions. If you use Command Prompt to run batch files, this limitation also applies to batch file processing.

The last command that we are trying to execute has a total length of 57536 characters. 

Thanks,
Manish

Mike Klein

unread,
Feb 9, 2017, 9:26:14 AM2/9/17
to skia-discuss
Ah, good.  This all makes sense.  

It looks like we use an response file when linking statically with a GCC-like tool chain but not for shared libraries.  (gn/BUILD.gn:593-621)  Can you see if patching in https://skia-review.googlesource.com/8242 fixes things for you?
Reply all
Reply to author
Forward
0 new messages