Search code examples
androidandroidxrenderscriptandroid-renderscript

Getting llvm-rs-cc process error, What am I doing wrong?


I am getting following ERROR for trying to run renderscript to invert image

Process 'command '/home/sandesh/Applications/AndroidStudio/Android/Sdk/build-tools/29.0.2/llvm-rs-cc'' finished with non-zero exit value 1

JAVA:

        RenderScript rs = RenderScript.create(context);
    ScriptC_clone scriptC_clone = new ScriptC_clone(rs);


    Allocation inputAllocation = Allocation.createFromBitmapResource(
            rs, context.getResources(), R.drawable.image_1);
    Allocation outputAllocation = Allocation.createTyped(
            rs, inputAllocation.getType(),
            Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT);
    scriptC_clone.invoke_process(inputAllocation, outputAllocation);

clone.rs:

#pragma version(1)
#pragma rs java_package_name(com.example.clone)


uchar4 RS_KERNEL invert(uchar4 in, uint32_t x, uint32_t y) {
   uchar4 out = in;
   out.r = 255 - in.r;
   out.g = 255 - in.g;
   out.b = 255 - in.b;
   return out;
}

void process(rs_allocation inputImage, rs_allocation outputImage) {
  const uint32_t imageWidth = rsAllocationGetDimX(inputImage);
  const uint32_t imageHeight = rsAllocationGetDimY(inputImage);
  rs_allocation tmp = rsCreateAllocation_uchar4(imageWidth, imageHeight);
  rsForEach(invert, inputImage, tmp);
}

GRADLE:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'
    defaultConfig {
    applicationId "com.example.clone"
    minSdkVersion 22
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    renderscriptTargetApi 19
    renderscriptSupportModeEnabled true

   }

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
sourceSets {
    main {
        jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/']
        renderscript.srcDirs =['src/main/rs', 'src/main/rs/']
}     }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation project(path: ':openCVLibrary348')
    implementation 'com.google.android.material:material:1.0.0'
}

Solution

  • There are probably other error lines above this (or in a separate console in Android Studio). Running this on the command line myself gives me this:

    sample.rscript:17:25: error: implicit declaration of function 'rsCreateAllocation_uchar4' is invalid in C99 sample.rscript:17:19: error: initializing 'rs_allocation' (aka 'struct rs_allocation') with an expression of incompatible type 'int'

    You need to target API level 24 or higher in order to use these additional features. You can't use them when targeting RS to only API 19 (which is older than the minimum API for the rest of your app - 22). It's possible to rewrite the code to support older RS versions, but you lose these nice helper routines.

    The header (and 24 API level) can be seen here: https://android.googlesource.com/platform/frameworks/rs/+/refs/heads/master/script_api/include/rs_allocation_create.rsh#382