Search code examples
androidgradleandroid-support-libraryrenderscript

RenderScript package does not exist - although added to build.gradle


I'm (again) struggling with a support library issue in my project. I want to use the RenderScript library for some image processing within my app. This project is one that I had taken over from someone else, and it's my first Android Studio/gradle project so far. As a consequence I still lack experience especially regarding all those gradle configuration files.

The problem is: I have included the following lines into my build.gradle file within the app module:

defaultConfig {
    ...
    renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    renderscriptSupportModeEnabled true
    ...
}

project.ANDROID_BUILD_TARGET_SDK_VERSION has been set to both, 15 and 22 within gradle.properties which made no real difference.

However, I always get errors like this whenever I compile the project:

Error:(12, 39) error: package android.support.v8.renderscript does not exist

The really strange thing is: If I create a new project from scratch and include the same two lines in build.gradle within the app module, I am able to use the RenderScript classes without problems. So I think it can't be a problem with my general configuration but has to be project related somehow. I'm just not sure how anything could cause such a behavior and disable the packages despite the correct lines in the gradle script.

One thing that might be important and made me wonder right from the start: When I first added those lines to the gradle script and created the import statements in my class files, Android studio asked if it should import some support library jar file as a library. I didn't know why this should be needed as the support classes shouldn't require any additional setup as far as I know. I agreed to import it, but as I said above the packages and classes still can't be found.

The complete build.gradle file from my project (that does not work):

apply plugin: 'com.android.application'

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        applicationId 'com.some.app'
        multiDexEnabled = true
        renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        renderscriptSupportModeEnabled true
        minSdkVersion Integer.parseInt(project.MIN_SDK)
        targetSdkVersion  Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    }

    signingConfigs {

        signingConfigs {

            debug {
                storeFile file('<some file>')
                keyAlias 'xxx'
                keyPassword 'xxx'
                storePassword 'xxx'
            }

            release {
                storeFile file('<some file>')
                keyAlias 'xxx'
                keyPassword 'xxx'
                storePassword 'xxx'
            }
        }
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
            debuggable false
            jniDebuggable false
            zipAlignEnabled true
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }


    dexOptions {
        javaMaxHeapSize "4g"
    }

}

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.0+'
    compile 'com.android.support:support-v4:22.2.0+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':firebase_plugin')
    compile project(':geofire')
    compile 'com.android.support:multidex:1.0.0'
    compile files('libs/acra-4.5.0.jar')
}

The build.gradle file of the app module from the dummy project (which does work):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.self.bitmapscaletest"
        minSdkVersion 15
        targetSdkVersion 22
        renderscriptTargetApi 15
        renderscriptSupportModeEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}

The larger project has multiple modules, could this be a problem? Do I also have to adjust the gradle scripts of those other modules?

Thank you in advance!


Solution

  • Shortly after posting I seem to have solved it. The different modules indeed seem to be the problem. After adding those two lines to the other modules' gradle.build the app compiles and launches.