Android Status

Ignacious via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 9 15:24:08 PST 2017


How difficult is it to build for x86/x64?

Would be nice to be able to use something like

http://www.android-x86.org/

as a test instead of an actual device.

Does one simply have to use the proper ldc2/dmd and link in the 
correct libs? or is it more complex?

Also, I'm a bit confused on how to compile the source 
examples(working it out and trying to explain the solutions as I 
type)

https://wiki.dlang.org/Build_DMD_for_Android

(set $NDK permanently)
I have done(easy, find the file and modify)

     rt_init();
     android_main(android_app);
     rt_term();

Clean up and compile as before:

$NDK/ndk-build clean
NDK_TOOLCHAIN_VERSION=clang $NDK/ndk-build V=1

But no error. Object files for various architectures are created 
though, it seems. (rt_ errors do no exist contrary to what is 
said in the docs)


But the following seems need updating/explaining. I am using 
prebuilt ldc2 for android from some link you provided. -android 
doesn't seem to work and I can't find sensor.d (not sure if it is 
needed anymore)?

../../../dmd/src/dmd -android -I../.. 
-ofobj/local/x86/objs/native-activity main.o -c jni/main.d 
../../android/sensor.d

I had to change to use ldc2, remove -android, and obviously 
change the file names and such(and download the android dir from 
github).

$NDK/toolchains/llvm-3.5/prebuilt/linux-x86/bin/clang 
-Wl,-soname,libnative-activity.so -shared 
--sysroot=$NDK/platforms/android-9/arch-x86 
./obj/local/x86/objs/native-activity/main.o 
./obj/local/x86/libandroid_native_app_glue.a -lgcc  
-gcc-toolchain  $NDK/toolchains/x86-4.8/prebuilt/linux-x86 
-target i686-none-linux-android -no-canonical-prefixes  
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  
-L$NDK/platforms/android-9/arch-x86/usr/lib -llog -landroid -lEGL 
-lGLESv1_CM -llog -lc -lm -fuse-ld=bfd
-L../../../phobos/generated/linux/release/32 -l:libphobos2.a -o 
./libs/x86/libnative-activity.so

Seems a lot of the paths are wrong/different than what I have

$NDK/toolchains/llvm-3.5/prebuilt/linux-x86/bin/clang 
-Wl,-soname,libhello-jni.so -shared 
--sysroot=$NDK/platforms/android-9/arch-x86 
./obj/local/x86/objs-debug/hello-jni/main.o 
./obj/local/x86/libandroid_native_app_glue.a -lgcc  
-gcc-toolchain  $NDK/toolchains/x86-4.8/prebuilt/linux-x86 
-target i686-none-linux-android -no-canonical-prefixes  
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  
-L$NDK/platforms/android-9/arch-x86/usr/lib -llog -landroid -lEGL 
-lGLESv1_CM -llog -lc -lm -fuse-ld=bfd 
-L../../../phobos/generated/linux/release/32 -l:libphobos2.a -o 
./libs/x86/libhello-jni.so


I am going to zip of what I have so you can see how the paths are 
laid out: http://www.filedropper.com/ldc2android

There seems to be no obj file generated except for debug, that 
was probably intentional but the given command line doesn't 
represent that if so.


It is a bit confusing for the beginner to come along and try to 
get all this to work when there is contradictory information. The 
reason being is simple in that a beginner won't know what is used 
for what and the docs essentially are give as "plug and play" yet 
don't actually work... rather than being descriptive and 
explaining exactly what is what(some of it should be obvious but 
not all will be to someone that isn't versed in linux and android 
development or used to windows which abstracts everything).

What would be nice, at a minim, is a bash script that allows one 
to adjust different variables for different situations and then 
it can be used to compile. (e.g., set the obj path, ndk path, 
ldc2 path, etc)

What really needs to be done, IMO, is to have a simple set of 
tools(scripts or whatever) that can be configured easily and 
abstracts the complexity. (I've done that for the test script I 
made

#!/bin/bash

/mnt/c/dlang/ldc2Android/bin/ldc2 -c $1.d

$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
-Wl,-z,nocopyreloc --sysroot=$NDK/platforms/android-9/arch-arm 
-lgcc -gcc-toolchain 
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 
-target armv7-none-linux-androideabi -no-canonical-prefixes 
-fuse-ld=bfd -Wl,--fix-cortex-a8 -Wl,--no-undefined 
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fPIE -pie -mthumb 
-Wl,--export-dynamic -lc -lm $1.o lib/libphobos2-ldc.a 
lib/libdruntime-ldc.a -o $1


which does the compiling for me without having to type all that 
junk in each time.. pretty simple but does the job, a more 
advanced concept could be used to help make it easier on people
)

If you want, and you can accomplish this, if there was an 
ldc2/dmd2 for android that runs on windows I could work on 
getting it working for windows(as I prefer it rather than linux, 
which I have no real experience with). I'm thinking everything 
more or less would work similarly(since sdk/ndk exists for 
windows). It would just be a matter of translating paths and 
such. I could easily write a wrapper to reduce the complexity.


The main problem I seem to be having are path issues(e.g,

$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang

rather than

$NDK/toolchains/llvm-3.5/prebuilt/linux-x86/bin/clang

,etc)


The final error I get is

clang: error: no such file or directory: 
'./obj/local/x86/libandroid_native_app_glue.a'

and I can't find this file anywhere.

I assume I was suppose to get this file when I did

$NDK/ndk-build clean
NDK_TOOLCHAIN_VERSION=clang $NDK/ndk-build V=1

You should see the following linker error, as the linker can't 
find the rt_init and rt_term functions you just added:

/home/joakim/android-ndk-r10/sources/android/native_app_glue/android_native_app_glue.c:232:
error: undefined reference to 'rt_init'
/home/joakim/android-ndk-r10/sources/android/native_app_glue/android_native_app_glue.c:234:
error: undefined reference to 'rt_term'
clang++: error: linker command failed with exit code 1 (use -v to 
see invocation)
make: *** [obj/local/x86/libnative-activity.so] Error 1

but I didn't.

If I execute that command in the android_native_app_glue.c dir I 
get

/opt/android-ndk-r13b/sources/android/native_app_glue# 
NDK_TOOLCHAIN_VERSION=clang $NDK/ndk-build V=1
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point 
to it.
/opt/android-ndk-r13b/build/core/build-local.mk:151: *** Android 
NDK: Aborting    .  Stop.

Of course, if I execute it in the project path I get a lot of 
stuff but not that file anywhere.

I have dried to put

android_native_app_glue.d

in different places but nothing...

Once that is fixed I assume everything should work... but I'm at 
a loss for what to do next. Any ideas?

Basically we have andorid_native_app_glue.c which we modify with 
rt_init and rt_term. We have a d file of that which I don't know 
what to do with. I see that somewhere in the compiling of the of 
the sample file that it is used but I'm unsure of what is what 
and how to go about getting android_native_app_glue.a(is it the d 
version compiled, something that comes from the ndk, or what?)



(sorry for the mess, was trying stuff as I went along)



More information about the Digitalmars-d-learn mailing list