How to use Orekit libraries in Android Studio

Hi everyone,

how I have to implement the Orekit libraries correctly in Android Studio after downloading? I never had to use libraries from other sources so I’m a litte bit confused now. I need both Orekit and Hipparchus-Math to start testing.
I copied all files to my working directory (Android Studio Project/OrekitApp/app/src/main/java/org/orekit). But now there are a lot of erros in DefaultDataContextPlugin.java (there is a ‘cannot resolve symbol’ at nearly every import instruction - for example 'import javax.annotation.processing.SupportedAnnotation Types; or import com.sun.source.tree.CompilationUnitTree;).

I hope I can find some help here.

Kind regards,

Patrick

Use the binaries instead of the sources is the easiest way to use Orekit. Using Maven (or one of it’s related tools) is the easiest way to use the binaries. See https://search.maven.org/artifact/org.orekit/orekit/10.1/jar

Hi,

As Evan said, you have to use the binaries. You can add and import binaries to your Android Studio project in the build.gradle file of your project (it is like the pom.xml file in Maven projects).
Inside the build.gradle file:

  1. Add a repositories entry in order to point Maven repository.
repositories {
    mavenCentral()
}

In addition, if you want to use your own binaries, located in your computer (generally in your .m2 folder), add mavenLocal() to the previous entry.

  1. Add a dependencies entry in order to list the libraries you want to import from Maven in your Android Studio project.
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'org.hipparchus:hipparchus-core:1.6'
    implementation 'org.hipparchus:hipparchus-filtering:1.6'
    implementation 'org.hipparchus:hipparchus-fitting:1.6'
    implementation 'org.hipparchus:hipparchus-geometry:1.6'
    implementation 'org.hipparchus:hipparchus-ode:1.6'
    implementation 'org.hipparchus:hipparchus-optim:1.6'
    implementation 'org.hipparchus:hipparchus-stat:1.6'
    implementation 'org.orekit:orekit:10.1'
}

If you have other dependencies (for instance local maven repository), add them to the previous key.

As far as I remember, don’t forget to update and refresh your gradle project. There is an icon in Android Studio IDE to do that (it is like Update Maven Project instruction in Eclipse IDE).

Regards,
Bryan

Thank you very much! I appreciate your help!

Kind regards,

Patrick

I put the implementations into my Gradle.build and did a sync. For testing I tried to put following code into MainActivity:
final String line1 = “1 37753U 11036A 12090.13205652 -.00000006 00000-0 00000+0 0 2272”;
final String line2 = “2 37753 55.0032 176.5796 0004733 13.2285 346.8266 2.00565440 5153”;
final TLE tle = new TLE(line1, line2);

I imported org.orekit.propagation.analytical.tle.TLE; but the app crashes permanently. Do I have to put the Orekit binary somewhere?

Thanks for your reply

Maybe you have to verify if the binaries are properly imported from Maven. If you are under a proxy, don’t forget to create a settings.xml file in your .m2 folder to set your proxy configuration.

I know that sometimes, with Android Studio, you have to restart the IDE to finalize the importation of the binaries

Perhaps I misunderstood something…
I created a new empty project and added the repositories entry and implementations in the build.gradle file.
Then I copied the orekit-10.1.jar binary into the libs folder and synced everything. At this state the app crashes.
I watched out for an example app and there are some classes where the Orekit data is installed. Here the example:
public class Install {

private static String orekitDataPath = "orekit-data";
private static String[] orekitFolders = {
        "Others",
        "DE-430-ephemerides",
        "Earth-Orientation-Parameters"+File.separator+"IAU-1980",
        "Earth-Orientation-Parameters"+File.separator+"IAU-2000",
        "MSAFE",
        "Potential"
};


/**
 * Returns file pointing to root directory of the orekit data
 * @param activity
 */
public static File getOrekitDataRoot(Activity activity){
    return new File(activity.getFilesDir()+File.separator+orekitDataPath);
}



/**
 * Installs the orekit files in the internal storage of the application
 * @param activity
 */
public static void installApkData(MainActivity activity){

   File check = new File(activity.getFilesDir() + File.separator + "orekit-data");
   System.out.println(check.getAbsolutePath());
   if(!check.exists()) {
       copyAssets(activity);
   } else
       System.out.println("Files already in storage.");

I’m sorry to ask such beginner questions.

Your questions are far to be beginner questions.

As I am not an expert of Android Studio, I can help you with two references:

First reference is the source code of a mobile application, developed in Android, using Orekit library. I know that this app has been develop under Android Studio IDE. In this respect it can help you (especially stavor/ folder).
Second reference is the official documentation for adding dependencies to an Android project.

Kind regards,
Bryan

Ok, thank you! I will try to figure out how to get it working

I get this error even when I try to create an object "final TLE tle = new TLE(String line1, String line2);:

2020-05-07 08:20:29.135 23393-23393/com.example.orekit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.orekit, PID: 23393
java.lang.BootstrapMethodError: Exception from call site #7 bootstrap method
    at org.orekit.data.DirectoryCrawler.feed(DirectoryCrawler.java:108)
    at org.orekit.data.DirectoryCrawler.feed(DirectoryCrawler.java:81)
    at org.orekit.data.DataProvidersManager.feed(DataProvidersManager.java:362)
    at org.orekit.data.AbstractSelfFeedingLoader.feed(AbstractSelfFeedingLoader.java:55)
    at org.orekit.time.TAIUTCDatFilesLoader.loadOffsets(TAIUTCDatFilesLoader.java:77)
    at org.orekit.time.LazyLoadedTimeScales.getUTC(LazyLoadedTimeScales.java:179)
    at org.orekit.propagation.analytical.tle.TLE.<init>(TLE.java:167)
    at com.example.orekit.SatelliteSelectActivity.onCreate(SatelliteSelectActivity.java:18)
    at android.app.Activity.performCreate(Activity.java:7327)
    at android.app.Activity.performCreate(Activity.java:7318)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
 Caused by: java.lang.ClassCastException: Bootstrap method returned null
    at org.orekit.data.DirectoryCrawler.feed(DirectoryCrawler.java:108) 
    at org.orekit.data.DirectoryCrawler.feed(DirectoryCrawler.java:81) 
    at org.orekit.data.DataProvidersManager.feed(DataProvidersManager.java:362) 
    at org.orekit.data.AbstractSelfFeedingLoader.feed(AbstractSelfFeedingLoader.java:55) 
    at org.orekit.time.TAIUTCDatFilesLoader.loadOffsets(TAIUTCDatFilesLoader.java:77) 
    at org.orekit.time.LazyLoadedTimeScales.getUTC(LazyLoadedTimeScales.java:179) 
    at org.orekit.propagation.analytical.tle.TLE.<init>(TLE.java:167) 
    at com.example.orekit.SatelliteSelectActivity.onCreate(SatelliteSelectActivity.java:18) 
    at android.app.Activity.performCreate(Activity.java:7327) 
    at android.app.Activity.performCreate(Activity.java:7318) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7050) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Hi @patrickk83, and welcome.

I’ve never used Orekit on Android, but from your stacktrace it seems like the orekit-data files (basically model data required for nearly all Orekit methods) are not initialized properly. There is a topic here with links to the documentation.

There may be Android specificities since you will probably have to work with the file system or application packaging system. Looking at the Stavor source code linked by @bcazabonne might provide answers.