简体   繁体   English

带Gradle的Android Renderscript

[英]Android Renderscript with Gradle

I'm building a Renderscript processing and for the life of me I can't make it work on gingerbread through Gradle. 我正在构建一个Renderscript处理器,对于我的生活,我不能通过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: 使用renderscriptTargetApi 18renderscriptSupportMode true与最新版本的工具buildToolsVersion "19.0.1"classpath 'com.android.tools.build:gradle:0.8.+'和gradle这个1.10它编译罚款,并在其上运行ICS +设备很好,但它使用以下堆栈跟踪在Gingerbread上崩溃:

 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 buildToolsVersionbuildToolsVersion

classpath : 0.7.+, 0.7.1 classpath :0.7。+,0.7.1

some of those needed gradle 1.9 to run, which I changed and run and crash. 其中一些需要gradle 1.9才能运行,我改变并运行并崩溃。

I've also tried including the following lines in my build.gradle 我也试过在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 ) 并根据此问题添加所有相关的二进制文件如何使用Gradle的Renderscript支持库,有时(取决于我正在尝试的版本)它编译和崩溃具有相同的错误,或由于重复声明而无法编译renderscript v8包上的方法名称( multiple dex files define android/support/v8/renderscript/Allocations

just for reference that's my module build.gradle: 仅供参考,这是我的模块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: 这是顶级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? 什么是正确的组合使其成功编译并在ICS +和Gingerbread上运行?

I don't think this is a Gradle bug--I think this is a known dynamic linking issue on Gingerbread and below. 我不认为这是一个Gradle错误 - 我认为这是姜饼及其下方已知的动态链接问题。 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. 使用Build-tools 21.1.0时,我对Android-Studio和Renderscript支持也有同样的问题。 This is what I found in build-system changelog lines 26-32: 这是我在build-system changelog行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文件夹中。

Hope this helps someone and saves some time. 希望这有助于某人并节省一些时间。

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

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