简体   繁体   English

如何在Gradle中使用Renderscript支持库

[英]How to use the Renderscript Support Library with Gradle

Is it possible to use the Support Renderscript Library with Gradle? 可以在Gradle中使用Support Renderscript库吗? If so, how do you include it in your project? 如果是这样,您如何将其包括在项目中?

Using Android Studio: 使用Android Studio:

Add the following values to build.gradle for android gradle plugin v0.14+ 添加以下值build.gradle用于安卓插件的gradle + v0.14

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

For older versions of the android gradle plugin v0.13.3 and below 对于较旧版本的android gradle插件v0.13.3及更低版本

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

Once that is done, use android.support.v8.renderscript. 完成后,请使用android.support.v8.renderscript. anywhere in your app. 您应用中任何位置。 The library jar and binaries are included automatically. 库jar和二进制文件自动包含在内。

Gradle for Android has now Renderscript v8 support with only 2 lines in your build script. Gradle for Android现在支持Renderscript v8,而您的构建脚本中只有2行。 See answer by Austyn Mahoney . 参见Austyn Mahoney的回答 Keeping the original answer for historical purpose. 保留原始答案用于历史目的。


Old Answer: 旧答案:

Gradle supports native RS compilation, but not the RS support library. Gradle支持本机RS编译,但不支持RS支持库。 The reason is that the RS support library is hugely complicated compared to any other support library. 原因是与任何其他支持库相比,RS支持库都非常复杂。 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. RS支持库实际上是Java支持库,支持该Java库的一组本机库,用于您编译的每个脚本的其他本机库,以及用于生成标准LLVM位代码和脚本的本机库的备用工具链。 Right now, only ADT and Ant support that; 目前,只有ADT和Ant支持。 Gradle isn't there yet. Gradle还不存在。

However, it's possible to use some parts of the RS support library from Gradle already. 但是,已经可以使用Gradle的RS支持库的某些部分。 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. 如果要使用RS内部函数,则可以链接支持库的Java部分(sdk / build-tools / android-4.3 / lib / renderscript / renderscript-v8.jar)和本机组件(sdk / build-tools /android-4.3/lib/renderscript/packaged/ <arch> / *。so),然后您会被设置。

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. 我知道Gradle在不久的将来会对支持库提供支持,但是我没有可以共享的坚定的ETA。

Following Tim's hint, I was able to get v8 support working with Gradle, here is my project layout: 按照Tim的提示,我可以在Gradle上获得v8支持,这是我的项目布局:

在此处输入图片说明

I created libs folder, and copied files Tim mentioned under the SDK folder. 我创建了libs文件夹,并复制了SDK文件夹下提到的Tim的文件。 And here is my build.gradle changes: 这是我的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'));
    }
}

After that, I can import android.support.v8.renderscript.* and use the intrinsics. 之后,我可以导入android.support.v8.renderscript。*并使用内部函数。

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. 我知道已经解决了这个问题,但是我想与Build-tools 21.1.0一起分享Android-Studio和Renderscript支持的经验。 This is what I found in build-system changelog lines 26-32: 这是我在构建系统变更日志第26-32行中发现的:

  • Renamed a few properties to make things more consistent. 重命名了一些属性以使事情更加一致。
    • BuildType.runProguard -> minifyEnabled BuildType.runProguard-> minifyEnabled
    • BuildType.zipAlign -> zipAlignEnabled BuildType.zipAlign-> zipAlignEnabled
    • BuildType.jniDebugBuild -> jniDebuggable BuildType.jniDebugBuild-> jniDebuggable
    • BuildType.renderscriptDebug -> renderscriptDebuggable BuildType.renderscriptDebug-> renderscriptDebuggable
    • ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled ProductFlavor.renderscriptSupportMode-> renderscriptSupportModeEnabled
    • ProductFlavor.renderscriptNdkMode -> renderscriptNdkModeEnabled ProductFlavor.renderscriptNdkMode-> renderscriptNdkModeEnabled

So you see, they have changed the properties name. 如此一来,他们已经更改了属性名称。 I just updated build.gradle to use: 我刚刚更新了build.gradle以使用:

renderscriptSupportModeEnabled true renderscriptSupportModeEnabled true

Now the libraries are added to the project and you don't need to manually add them to your lib folder. 现在,这些库已添加到项目中,您无需手动将它们添加到您的lib文件夹中。

There is experimental support in the Gradle Android plugin at the time of this writing. 在撰写本文时,Gradle Android插件中有实验性支持。 See this test project for more info. 有关更多信息,请参见此测试项目

If anyone is interested in how to package this as a distributable binary .jar (eg for deploying to a maven repo) you can use this file structure for your .jar. 如果有人对如何将其打包为可分发的二进制.jar(例如,用于部署到Maven存储库)感兴趣,则可以将此文件结构用于.jar。

整体档案结构Java类

pom.xml: 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. 对于build.gradle,在您的依赖项clojure中添加: compile 'android:renderscript:19.0.3'

PS: The renderscript library won't run on armv6 (armeabi), so make sure that Build.CPU_ABI is either armeabi-v7a, mips or x86. PS:renderscript库无法在armv6(armeabi)上运行,因此请确保Build.CPU_ABI是armeabi-v7a,mips或x86。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM