0

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/YYYClass.java:55: 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:

./asubmodule/src/main/rs/xxx.rs (using package declaration #pragma rs java_package_name(apackage.scripts))

./asubmodle/src/main/java/apackage/YYYClass.java

./asubmodule/target/android/generated/source/android/support/v7/appcompat/R.java

./asubmodule/target/android/generated/source/apackage/scripts/ScriptC_xxx.java

silvaren
  • 730
  • 6
  • 14
  • Looking at [sbt-android source](https://github.com/scala-android/sbt-android/blob/master/src/tasks.scala#L654), all generated `.java` files are identified because they are listed in the old `.d` RenderScript dependency file ([example](https://github.com/degrigis/polimi_projects/blob/master/androBenchmark/bin/rsDeps/filter.d)). However, this kind of file does not get generated necessarily (and, probably, not even anymore in the latest RenderScript versions). Can you check if there exists such a file in your build path? – cmaster11 Aug 04 '16 at 21:11
  • @cmaster11 I did check with "find . -name *.d", and it seems there is no .d file being generated. You mean it might be a bug in sbt-android? – silvaren Aug 04 '16 at 22:09
  • Exactly. Probably the build tools changed in latest releases, and the `.d` file generation process got wiped out or just had a good reason to not be used anymore. – cmaster11 Aug 04 '16 at 22:17
  • Are your renderscript sources in src/main/rs as expected? – pfn Aug 05 '16 at 04:19
  • @pfn yes. But I just realized something, it seems that the java classes for the scripts are being generated, but somehow the classes that use them cannot find them. Maybe I'm missing some kind of class path configuration for sbt-android? – silvaren Aug 05 '16 at 04:38
  • @pfn added a file structure part on the question above so maybe it might be clear why the build is not finding the generated script classes. – silvaren Aug 05 '16 at 04:49
  • Without the `.d` file, sbt-android doesn't know what java files were generates for renderscript. A new way of detecting the generated files will have to be implemented. In the mean time you can decrease build tools version until it works. I know for a fact 22.0.1 works – pfn Aug 05 '16 at 14:14

1 Answers1

2

Unfortunately, it seems com.android.builder.core.AndroidBuilder no longer generates .d files for processed renderscript sources. Bypassing AndroidBuilder to use com.android.sdklib.build.RenderScriptProcessor 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 ** "*BitCode.java").get
}.taskValue

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 https://github.com/scala-android/sbt-android/commit/ec09a55233aabd50e7df0085b10c567e38b616d3

pfn
  • 1,820
  • 12
  • 11
  • ok, I'm new to sbt, so I might have missed something. I created a new build.sbt file with your code, but it complained about some of the syntax. I came up with the following build.sbt, which still gives me the not found script classes errors. Is this the build.sbt that you had in mind? androidBuild platformTarget in Android := "android-23" sourceGenerators in Compile += Def.task { implicit val output = outputLayout.value val layout = projectLayout.value (layout.generatedSrc ** "ScriptC_*.java").get ++ (layout.generatedSrc ** "*BitCode.java").get }.taskValu – silvaren Aug 05 '16 at 17:12
  • What? are you importing from gradle or not? If yes, then all you put into build.sbt is what I stated. – pfn Aug 05 '16 at 18:52
  • I meant that if your code is all I put in the build.sbt file it will complain with this: $ sbt app/android:run [info] Loading global plugins from /x/x/.sbt/0.13/plugins [info] Loading project definition from /x/x/workspace/y/project Loading cached gradle project definitions [error] [/x/x/workspace/y/build.sbt]:2: '=>' expected but '=' found. Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? – silvaren Aug 05 '16 at 18:57
  • if you want to get support, use gitter. stackoverflow is frustring. – pfn Aug 05 '16 at 18:57
  • I should! Thanks! will do – silvaren Aug 05 '16 at 18:58