Skip to content

Commit

Permalink
Mentioning other architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
MrcSnm committed Jul 30, 2020
1 parent dd8d14f commit 22d1394
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Now you need to include an Android architecture lib on your LDC, to do that, go
Go into the [releases](https://github.com/ldc-developers/ldc/releases/)
Find for a release that matches your LDC version, as the time I'm writing this, my version is 1.22.0, so, it will have prefix like **ldc2-1.22.0-linux**
What you're searching for is the android architecture 64 (aarch64), so the version I needed to download is: *ldc2-1.22.0-linux-aarch64.tar.xz*

**IMPORTANT**
> If your target architecture does not have a prebuilt binary(Those one that are in the LDC developers release assets), you will have to [build it yourself the Phobos and the DRuntime](https://wiki.dlang.org/Building_LDC_runtime_libraries)
After downloading it, it's time to setup your compiler to find its existence.

## Adding compilation command
Expand Down Expand Up @@ -118,6 +122,11 @@ ldc2 sieve.d
```
If it compiles well, your LDC is correctly configured to start working with Android.

Before going to the next part of this tutorial, I would like to increment that this architecture is used as a sample because this is my phone's
respective architecture, if you wish to compile for any other architecture, take a look at [Cross Compiling with LDC](https://wiki.dlang.org/Cross-compiling_with_LDC)



# Preparing your D module for Android
After your first succesful try of compiling it to the Android architecture, you will actually need to do three things:
1. You will need to import the D module jni on the top of your file: `import jni`. The JNI module was not made by me, the file in this repository is
Expand Down Expand Up @@ -185,8 +194,10 @@ Test
|--Test.iml
```
And in the end there are:
> External Libraries
> Scratches and Consoles
```
|> External Libraries
|> Scratches and Consoles
```
Open the folder Test/app/src/main and inside main, create a folder called `jniLibs`, this folder is **extremely important**, it is the default folder to
put your shared libraries to be imported together with your .apk. If you wish to use other name for it, you will need to change your gradle file.
For actually putting your libraries inside that folder, you will actually need to make directories for the target architectures, so, create inside it:
Expand Down
3 changes: 2 additions & 1 deletion sample.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import jni;
import std.conv : to;
import std.string;
import core.runtime : rt_init;
extern(C) jstring Java_my_long_package_name_ClassName_methodname(JNIEnv* env, jclass clazz, jstring stringArgReceivedFromJava)
{
Expand All @@ -8,6 +9,6 @@ extern(C) jstring Java_my_long_package_name_ClassName_methodname(JNIEnv* env, jc
string javaStringInDStyle = to!string(javaStringInCStyle);
(*env).ReleaseStringUTFChars(env, stringArgReceivedFromJava, javaStringInCStyle);

return (*env).NewUTFString("Hello from D, myarg: "~javaStringInDStyle);
return (*env).NewUTFString(toStringz("Hello from D, myarg: "~javaStringInDStyle));
}
void main(){}

0 comments on commit 22d1394

Please sign in to comment.