Question

I am working on an App which is meant to use the Renderscript Support Library. For development Android Studio 0.5.4 and Gradle 1.11 is used.

To configure renderscript I use

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        renderscriptTargetApi 19
        renderscriptSupportMode true

    }
}

This works on 2.3 and 4.4.2.

After my first screen I wanted to write a few tests to document. Atm I use ActivityUnitTestCase as the ancestor for the tests.. My test code is in src/androidTest/java and is identified by Android Studio as a src directory. I can also successfully start the test case using a real device. The test case itself just verifies the existence of a few views. However the tests fail because of:

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

Further down in the stack trace I see that its triggered shortly before the first renderscript invocation. Having a look inside the generated (not obfuscated) apk shows that the Instrumentation Test apk contains the android.support.v8.renderscript package.

So the exception arises because both the apk under test and the test include the renderscript package.

My Question: How to prevent it?

I use several libraries and they do not appear in the test apk. Just the renderscript library does with both dex files and shared objects. I assume its due to its deep native complexity that its treated differently than libraries like nineoldandroids etc.

My Google-Fu revealed that there are only workarounds, one of them being http://www.sinking.in/blog/android-dependency-double-trouble/ Which also mentions the inheritent problem http://issues.gradle.org/browse/GRADLE-784

But non of the fixes mentioned there apply to the renderscript lib.

Im thankful for any hint. Thank you.

Was it helpful?

Solution

It seems to be a limitation on the current gradle logic for handling the support renderscript lib. I work around it by copying the renderscript-v8.jar and the pre packaged *.so files from /build-tools/19.0.3/renderscript to the appropriate project.

The *.so files are added under main/jniLibs and are automatically detected and deployed to the appropriate build variant (arm7, mips, x86).

The jar needs to be announced in the gradle file because the buildsystem ignores jar files by default:

dependencies{
    compile files('libs/renderscript-v8.jar')
}

The benefit of this approach is that when building the test apk the renderscript support package is not deployed in the test apk and thus the tests run without interference of the bug mentioned in the question (java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation)

It would be smarter to use

renderscriptTargetApi 19
renderscriptSupportMode true

Because that way the current performance enhancements are applied to the appropriate app and it looks cleaner, thus easier to maintain. But for my part testability > less overhead in update behaviour.

Once the renderscriptSupportMode directive works properly I switch back.

OTHER TIPS

According to this stackoverflow answer (a developer at etsy) renderscript does not work with gradle. Blur effect like in the app Etsy? I don't know why, just read this a couple of days ago.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top