How to use the Renderscript Support Library with Gradle

你说的曾经没有我的故事 提交于 2019-12-17 06:35:34

问题


Is it possible to use the Support Renderscript Library with Gradle? If so, how do you include it in your project?


回答1:


Gradle for Android has now Renderscript v8 support with only 2 lines in your build script. See answer by Austyn Mahoney. Keeping the original answer for historical purpose.


Old Answer:

Gradle supports native RS compilation, but not the RS support library. The reason is that the RS support library is hugely complicated compared to any other support library. The RS support library is actually a Java support library, a set of native libraries backing that Java lib, additional native libraries for every script you compile, and an alternate toolchain for generating both the standard LLVM bitcode and the native libraries for your scripts. Right now, only ADT and Ant support that; Gradle isn't there yet.

However, it's possible to use some parts of the RS support library from Gradle already. If you want to use the RS intrinsics, you can link the Java part of the support library (sdk/build-tools/android-4.3/lib/renderscript/renderscript-v8.jar) and the native components (sdk/build-tools/android-4.3/lib/renderscript/packaged/< arch >/*.so), and then you'll be set.

I know Gradle support for the support library is coming at some point in the not too distant future, but I don't have a firm ETA that I can share.




回答2:


Using Android Studio:

Add the following values to build.gradle for android gradle plugin v0.14+

android {
    ...
    defaultConfig {
        ...
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    ...
}

For older versions of the android gradle plugin v0.13.3 and below

android {
        ...
        defaultConfig {
            ...
            renderscriptTargetApi 19
            renderscriptSupportMode true
        }
        ...
    }

Once that is done, use android.support.v8.renderscript. anywhere in your app. The library jar and binaries are included automatically.




回答3:


Following Tim's hint, I was able to get v8 support working with Gradle, here is my project layout:

I created libs folder, and copied files Tim mentioned under the SDK folder. And here is my build.gradle changes:

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'));
    }
}

After that, I can import android.support.v8.renderscript.* and use the intrinsics.




回答4:


I know this has been already answered, but I thought I'd share my experience 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.




回答5:


There is experimental support in the Gradle Android plugin at the time of this writing. See this test project for more info.




回答6:


If anyone is interested in how to package this as a distributable binary .jar (e.g. for deploying to a maven repo) you can use this file structure for your .jar.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>android</groupId>
  <artifactId>renderscript</artifactId>
  <version>19.0.3</version>
  <description>Artifactory auto generated POM</description>
</project>

For build.gradle, add: compile 'android:renderscript:19.0.3' to your dependencies clojure.

PS: The renderscript library won't run on armv6 (armeabi), so make sure that Build.CPU_ABI is either armeabi-v7a, mips or x86.



来源:https://stackoverflow.com/questions/19658145/how-to-use-the-renderscript-support-library-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!