I'm building a Renderscript processing and for the life of me I can't make it work on gingerbread through Gradle.
The processing uses both Intrinsics and custom Kernels.
using renderscriptTargetApi 18
and renderscriptSupportMode true
with the latest build tools buildToolsVersion "19.0.1"
and classpath 'com.android.tools.build:gradle:0.8.+'
and gradle 1.10 it compiles fine and it runs fine on ICS+ devices, but it crashes on Gingerbread with the following stack trace:
Caused by: android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Couldn't load RSSupport: findLibrary returned null
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:945)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:982)
at android.support.v8.renderscript.RenderScript.create(RenderScript.java:968)
I've also tried with a variety of the following versions:
buildToolsVersion
: 18.1.1, 18.1
classpath
: 0.7.+, 0.7.1
some of those needed gradle 1.9 to run, which I changed and run and crash.
I've also tried including the following lines in my build.gradle
dependencies {
compile files('libs/renderscript-v8.jar')
}
android {
tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
pkgTask -> pkgTask.jniFolders = new HashSet<File>();
pkgTask.jniFolders.add(new File(projectDir, 'libs'));
}
}
and add all the relevant binaries as per this question How to use the Renderscript Support Library with Gradle and sometimes (depending on which versions I'm trying) it compiles and crashes with the same error, or doesn't compile because of duplicate declaration of method names on the renderscript v8 package (multiple dex files define android/support/v8/renderscript/Allocations
)
just for reference that's my module build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
versionCode 1
versionName "1.0"
renderscriptTargetApi 18
renderscriptSupportMode true
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
}
and that's the top level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
so the question:
What is the correct combination to make it compile successfully and run on both ICS+ and Gingerbread?
I don't think this is a Gradle bug--I think this is a known dynamic linking issue on Gingerbread and below. Try adding the following to your Activity:
static {
System.loadLibrary("RSSupport");
System.loadLibrary("rsjni");
}
you might have to reorder those, I forget the exact nature of the linking issue.
I had the same issue with Android-Studio and Renderscript support with Build-tools 21.1.0. This is what I found in build-system changelog lines 26-32:
- Renamed a few properties to make things more consistent.
- BuildType.runProguard -> minifyEnabled
- BuildType.zipAlign -> zipAlignEnabled
- BuildType.jniDebugBuild -> jniDebuggable
- BuildType.renderscriptDebug -> renderscriptDebuggable
- ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
- ProductFlavor.renderscriptNdkMode -> renderscriptNdkModeEnabled
So you see, they have changed the properties name. I just updated build.gradle to use:
renderscriptSupportModeEnabled true
Now the libraries are added to the project and you don't need to manually add them to your lib folder.
Hope this helps someone and saves some time.
来源:https://stackoverflow.com/questions/21836164/android-renderscript-with-gradle