The following source code shows a minimal example for a BaseX class.
<syntaxhighlight pre lang="java">
public class BaseXDatabase {
private Context basexContext = null;
}
</syntaxhighlightpre>
This class can be called in every Android application which uses the BaseX library with the following call, for example:
<syntaxhighlight pre lang="java">
BaseXDatabase baseXDatabase = new BaseXDatabase(getApplicationInfo().dataDir);
</syntaxhighlightpre>
At the moment it is not possible to use the BaseX library, therefore more adjustments have to be done in the BaseX code.
The following code shows the changes inside the Context.java file:
<syntaxhighlight pre lang="java">
public Context(String data_dir) {
this(true, (Prop.HOME = data_dir + "/"), (Prop.USERHOME = data_dir + "/"));
this(new MainProp(file));
}
</syntaxhighlightpre>
As shown in the adjustment above, it is necessary to set the two variables 'Prop.HOME' and Prop.USERHOME' during the constructor call. In the BaseX code those variables are final, which need also be changed in order to set them during the call.
The reason for this change is that the in BaseX used System.getProperty(user.dir) returns an empty string in Android[httphttps://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)empty string in Android].
----
The following lines need to be removed:
<syntaxhighlight pre lang="java">
/** XQuery function. */
_CRYPTO_HMAC(FNCrypto.class, "hmac(message,key,algorithm[,encoding])",
URIS.put(FNCrypto.class, CRYPTOURI);
</syntaxhighlightpre>
The result of this adjustment is, that it is now possible to use BaseX as an Android library, with the lack of support of the following XQuery functions:
An example of this can be seen in the following code:
<syntaxhighlight pre lang="java">
public String executeXQuery(String query) throws IOException {
if(basexContext != null)
return "";
}
</syntaxhighlightpre>
This methods of the BaseXDatabase class can now be used in every Android application which includes the created BaseX Android library.
It is possible to create a .jar, or an .aar[http://tools.android.com/tech-docs/new-build-system/aar-format.aar file] file out of the BaseX library, by just building the source code.
This file need to be copied inside the lib folder of the Android project which wants to use the library. Additionally the build file of the application needs to be adjusted to use the library.
Using Gradle, the Android build system, it can be done by adding the following line to the gradle build file. This tells the build system that every library, inside the libs folder, is being compiled into the projects file.
<syntaxhighlight pre lang="java">
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
</syntaxhighlightpre>