Import package from another extension

I have two native extension,A.java in one and B.java in another, how can I import A.java from B.java?
BTW, A.java have different package than B.java.

2 Likes

Currently, it’s not possible. We’d like the same feature for C++ as well, in order to build extensions with more commonly used functionality (e.g OpenSSL etc)

I didn’t find a ticket for it though, so I created one: DEF-3348
I don’t think it will be done until a few months from now though.

2 Likes

So,is it isolated between extensions?Extension can only be used by lua or script or gui_script?

1 Like

Extension can be used by script and gui_script and module.

If you have A.java and B.java you could merge them into the same extension as well.

2 Likes

OK,got it

1 Like

I put A.java and B.java into one extension, and A.java with first line package a.b.c.d, B.java with first line package e.f.g.h;
when I import a.b.c.d; in B.java, It builds failed.How can I fix this?

What does the error say?

It says:
cannot find symbol
import xxxxxxx;

It should be possible, we just did such a test:

A.java

package a.b.c.d;

public class A {
    public static void LOL()
    {
        System.out.println("LOL");
    }
}

B.java

package e.f.g.h;

import a.b.c.d.A;

public class B {
    public static void LOL2() {
        A.LOL();
    }
}

Here is the full extension we used:
testext.zip (1.3 KB)

3 Likes

OK,I’ll try it out.

1 Like

Does the java file must be in the src folder?I found if I place A.java outside src folder, It won’t be bundled in classes.dex

Yes, the source files need to be placed in the src folder: https://www.defold.com/manuals/extensions/