Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building shared libraries targeting Linux #5

Closed
MichalStrehovsky opened this issue Jun 25, 2021 · 6 comments
Closed

Support building shared libraries targeting Linux #5

MichalStrehovsky opened this issue Jun 25, 2021 · 6 comments

Comments

@MichalStrehovsky
Copy link
Member

Shared libraries can only be created for Windows right now.

@opcodewriter
Copy link

Just to be sure I understand correctly, right now it's not possible to create a library for Android?

I'd like to write a method which takes an instance of a android.view.View for example, something like this:

public static class UtilityLib {
     public static void UpdateView(android.view.View view) {
            // ....
     }
}

@MichalStrehovsky
Copy link
Member Author

It works now. I don't know why I left this open. See the DynamicLibrary sample under samples in this repo.

@opcodewriter
Copy link

@MichalStrehovsky I'm confused. But how do I reference a class from Android? I.e. android.view.View

@MichalStrehovsky
Copy link
Member Author

If you want that, you should use Xamarin or MAUI.

Bflat will only let you build libraries that don't have luxury access to the Java world. You would use the library like this: https://github.com/android/ndk-samples/tree/main/hello-jni

@opcodewriter
Copy link

Thanks for reply. I was looking for a way other than Xamarin due to performance reasons.

@endlesstravel
Copy link

Now is v8.0.1。I just call C# dll from android (arm64) Activity ! (greate work bflat ! and jna !) 🤙 👍 🥰 (no need NDK !)

@MichalStrehovsky @opcodewriter

here is my progress:

  1. write a C# code (Program.cs):
class LIB
{
    [System.Runtime.InteropServices.UnmanagedCallersOnly(EntryPoint = "addx")]
    static int MainExport(int a, int b)
    {
        System.Console.WriteLine("MainExport C#");
        return a + b;
    }
}
  1. build with bflat :
bflat build -o:./output/liblinux-arm64.dll     --arch:arm64 --os:linux  --libc:bionic
  1. add jna lib to android project with implementation 'net.java.dev.jna:jna:5.14.0'. just like below image:
    图片

  2. add jniLibs describe in build.gradle, just like below image:
    图片
    you can copy code here:

    sourceSets {
        main.jniLibs.srcDirs = ['libs']
    }
  1. download jna jar file: https://github.com/java-native-access/jna/blob/master/dist/android-aarch64.jar and unzip android-aarch64.jar to get libjnidispatch.so file.
    图片

  2. first put liblinux-arm64.dll rename to liblinux-arm64-dll.so at lib/arm64-v8a. than put libjnidispatch.so at lib/arm64-v8a
    . just like below image:

图片

  1. create jna interface file, code here:
package com.example.myapplication;
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface MyLibraryx  extends Library {
    MyLibraryx INSTANCE = Native.load("linux-arm64-dll", MyLibraryx.class);
    int addx(int a, int b);
}

图片

  1. last just use it with MyLibraryx.INSTANCE.addx(1100, 2000) !
    图片

10 running screenshot:
图片

I haven't explored other things yet (string\float\function pointer \ load opengl libray ..... more )

But I can't wait to tell you all !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants