silvaren silvaren - 10 months ago 108
Scala Question

How to use sbt-android to build scala android projects with RenderScript files?

It seems that sbt-android is ignoring the presence of the RenderScript files and is not generating the ScriptC_xxx java classes that are normally generated by gradle builds/Android Studio [UPDATE: this is false, se the update note below]. Because of this issue, the sbt-android build is failing because to use the scripts we need to reference the generated ScriptC_xxx classes, which gives the following error when building:

[error] apackage/ cannot find symbol
[error] symbol: class ScriptC_xxx
[error] location: class apackage.YYYClass
[error] ScriptC_xxx xxxScript = new ScriptC_xxx(rs);

The generated .sbt file from the existing project (which compiles normally by gradle) has the apparent necessary configuration for RenderScript, generated from the build.gradle file:

rsTargetApi in Android := "18",
rsSupportMode in Android := rsSupportMode.value || true

What I am missing to be able to compile renderscript-containing android projects with sbt-android ?

UPDATE: I realized that the java classes for the scripts are being generated correctly, but somehow the classes that use those generated classes cannot find them, so maybe I have a classpath configuration problem.

This is the current file structure:

(using package declaration
#pragma rs java_package_name(apackage.scripts)





Unfortunately, it seems no longer generates .d files for processed renderscript sources. Bypassing AndroidBuilder to use in sbt-android could restore the .d files that are required to determine the generated files. But that would be a solution for a future version of sbt-android.

To work around your problem for now, you can add the following into your build.sbt:

sourceGenerators in Compile += Def.task {
  implicit output = outputLayout.value
  val layout = projectLayout.value
  (layout.generatedSrc ** "ScriptC_*.java").get ++ (layout.generatedSrc ** "*").get

Since it sounds like you're using sbt-android-gradle you can just create a new file build.sbt and throw the above in (do not edit the 00-gradle-generated.sbt)

Update: this will be fixed in the next version of sbt-android