5

I've just started renderscript in Android Studio. When I make a .rs file, both ScriptC_DS class and a .bc file is not being generated. I've read that it's supposed to be auto-generated once the .rs file is saved, so I'm not sure what's going wrong.

DS.rs

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

void root(){

}

build.gradle

 apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.example.DSing"
    minSdkVersion 16
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
    renderscriptTargetApi 18
    renderscriptSupportMode true

}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

The MainActivity class currently has nothing (aside from auto generated defaults), but when I try to create private ScriptC_DS inside, I get a message saying "Cannot resolve symbol ScriptC_DS." MainActivity

package com.example.DSing

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v8.renderscript.*;


public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
private ScriptC_DS test;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

Question: What am I doing wrong?

2
  • Where is your RenderScript source located? Jul 25, 2014 at 15:00
  • @LarrySchiefer It's located in the folder app/src/main/java/com.example.DS/. In there I have the .rs file and my MainActivity class
    – David
    Jul 29, 2014 at 22:37

2 Answers 2

17

The problem you are having is because the default project layout in Android Studio is different than that of Eclipse. You could see this from the app/src/main/java layout. The poorly documented piece is that RenderScript (and AIDL) now get their own directories in the source set rather than getting thrown into the Java source. Move your code to app/src/main/rs and Android Studio will build it properly and generate the .bc file asset.

2
  • Pretty late, but is the app/src/main/rs supposed to be auto generated? I had to make my own directory labeled "rs" under main to place the .rs file in.
    – David
    Aug 12, 2014 at 20:17
  • No, it won't be auto-generated for you like the 'java' directory is. Same thing with 'aidl' for AIDL defined binder interfaces. Aug 12, 2014 at 21:33
2

Larry's answer is right, all you need to do is

  1. add these two settings in your gradle config renderscriptTargetApi 18 renderscriptSupportModeEnabled true

  2. create folder for path /src/main/rs

rebuild your project, then you can get ScriptC_xxx to use.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.