1

I am attempting to write an Android app using the Frege language. Unfortunately, I'm not aware of any examples of how to do this.

So, I'm using Gradle as my build system, with the Android Gradle plugin. Then to get the Frege code to be compiled, I'm using a javaexec to call the frege compiler before the Java files get compiled, as suggested in this post.

I was successful in building an Android application with Frege code that gets called by Java code, as shown here.

However, the Frege code can only call standard Java APIs. It can't call any of the Android APIs.

I'd like to be able to call Android APIs from Frege. There is a nice repo here that has Frege wrappers for the Android APIs. Unfortunately, it has no build system or instructions.

I believe I've successfully set up my build.gradle to build the FregeAndroid wrappers along with my project's code. The Frege compiler is indeed attempting to build them.

However, the FregeAndroid code fails to compile, because it can't see the Android API classes. I assume I need to somehow find where the Android API classes are, and then add that to the Frege compiler's classpath, so it can see those classes. Unfortunately, this is where I'm stuck. I'm a newbie at Gradle, and can't figure out how to do this.

Here is my project which I have so far, which fails to build, in the following way:

:compileDebugJavaWithJavac
Frege compiler args: "-inline -d src/frege -make -fp /Users/ppelleti/Library/Android/sdk/platforms/android-21/android.jar -sp /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src/frege/android/animation/TimeInterpolator.fr"
calling: javac -cp /Users/ppelleti/.gradle/caches/modules-2/files-2.1/org.frege-lang/frege/3.23.401-g7c45277/716990197271fdc15917b4f8d023d63009ba6e39/frege-3.23.401-g7c45277.jar:/Users/ppelleti/Library/Android/sdk/extras/android/m2repository/com/android/support/multidex/1.0.0/multidex-1.0.0.aar:src/frege:/Users/ppelleti/Library/Android/sdk/platforms/android-21/android.jar -d src/frege -sourcepath /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src -encoding UTF-8 src/frege/frege/android/animation/TimeInterpolator.java 
runtime 4.282 wallclock seconds.
Frege compiler args: "-inline -d src/frege -make -fp /Users/ppelleti/Library/Android/sdk/platforms/android-21/android.jar -sp /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src/frege/android/app/Activity.fr"
Android.app.TaskStackBuilder: build failed because module is not on class path
Android.app.Fragment: build failed because module is not on class path
Android.app.LoaderManager: build failed because module is not on class path
[... omitted a bunch of similar lines ...]

Any ideas would be much appreciated!

user31708
  • 630
  • 5
  • 11
  • Did you try putting it as a compile dependency in the "dependencies" block just beneath the reference to the Frege version? – Dierk Sep 20 '16 at 13:31
  • ```dependencies { compile 'org.frege-lang:frege:3.23.401-g7c45277' compile '' compile 'com.android.support:multidex:1.0.0' }``` – Dierk Sep 20 '16 at 14:54
  • not a gradle expert, but maybe you can augment the command line args with -fp – Ingo Sep 20 '16 at 18:21
  • @Dierk, shouldn't the Android classes be an implicit dependency when using the Android plugin? The Java compiler can find them just fine. – user31708 Sep 22 '16 at 08:09
  • @Ingo, I tried adding -fp and the build output was the same as before. However, I noticed that the failed classes are in packages that start with a capital letter. So, that would suggest that it's the Frege wrappers that are not being found, not the classes in the android.jar? I've edited my question to include build output; I should have included that to begin with. – user31708 Sep 22 '16 at 08:09
  • Indeed, looks like wrapper classes frege.android..... Can you covince gradle to print the command line it is running, ? – Ingo Sep 22 '16 at 14:26
  • Perhaps you have a problem not with the class path, but with the source path (-sp option) too? Since it looks like it should compile, e.g. `frege/android/database/Cursor.fr` but doesn't find it. To make it work, the source path should contain the directory from whence the relative path `frege/android/database/Cursor.fr` would actually reference the source file. – Ingo Sep 22 '16 at 22:08
  • @Ingo, thanks! Between your previous two comments, I think I have a hypothesis what is going on. The arguments to the Frege compiler are, for example `-inline -d src/frege -make -sp FregeAndroid/src /Users/ppelleti/programming/android/frege-on-android/FregeAndroid/src/frege/android/app/Activity.fr`, so I think the problem is that the -sp is relative, but the filename is absolute. I'll try to figure out how to fix that problem, and then I'll let you know if it works. – user31708 Sep 23 '16 at 06:53
  • That should be ok, since only module names are resolved against the sp. But are you sure it must be `src/frege` rather than `src/` or `src/frege/main` ? This would imply you have `src/frege/frege/android/database/Cursor.fr` – Ingo Sep 23 '16 at 07:08

1 Answers1

0

It turns out that there were several problems, including problems with both the source path and the classpath. I've updated my repository to fix these problems.

However, ultimately the build fails because there are files missing from the FregeAndroid repo. So to get my example to build, it would be necessary to fix the FregeAndroid wrappers or write new wrappers.

user31708
  • 630
  • 5
  • 11