android - RenderScript 包不存在 - 尽管已添加到 build.gradle

标签 android gradle android-support-library renderscript

我(再次)在项目中遇到支持库问题。我想在我的应用程序中使用 RenderScript 库进行一些图像处理。这个项目是我从别人那里接手的,也是我迄今为止第一个Android Studio/gradle项目。因此,我仍然缺乏经验,特别是对于所有这些 gradle 配置文件。

问题是:我已将以下几行包含到应用程序模块内的 build.gradle 文件中:

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

project.ANDROID_BUILD_TARGET_SDK_VERSION 已在 gradle.properties 中设置为 15 和 22,这没有真正的区别。

但是,每当我编译项目时,我总是会遇到这样的错误:

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

真正奇怪的是:如果我从头开始创建一个新项目并在应用程序模块内的 build.gradle 中包含相同的两行,我就可以毫无问题地使用 RenderScript 类。所以我认为这不可能是我的一般配置的问题,但必须以某种方式与项目相关。我只是不确定为什么会导致这种行为并禁用软件包,尽管 gradle 脚本中的行是正确的。

有一件事情可能很重要,让我从一开始就想知道:当我第一次将这些行添加到 gradle 脚本并在我的类文件中创建导入语句时,Android studio 询问是否应该导入一些支持库 jar 文件作为图书馆。我不知道为什么需要这样做,因为据我所知,支持类不需要任何额外的设置。我同意导入它,但是正如我上面所说,仍然找不到包和类。

我的项目中的完整 build.gradle 文件(该文件不起作用):

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')
}

虚拟项目中应用程序模块的 build.gradle 文件(确实工作):

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'
}

较大的项目有多个模块,这会是一个问题吗?我还需要调整其他模块的 gradle 脚本吗?

提前谢谢您!

最佳答案

发布后不久,我似乎已经解决了这个问题。不同的模块似乎确实是问题所在。将这两行添加到其他模块的 gradle.build 后,应用程序将编译并启动。

关于android - RenderScript 包不存在 - 尽管已添加到 build.gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31806720/

相关文章:

android-support-library - 使用 PreferenceFragmen 的 CheckBoxPreference 将支持库升级到 23.2.0 和 ResourceNotFoundException

android - 在 android-support-v13 中找不到 DrawerLayout

java - GSON 库的 toJson() 返回错误的 json

android studio 没有链接到缺少的资源

Gradle shadowJar 删除所需的 SQL 驱动程序

gradle - Gradle错误无法将类 'lib'的对象 'java.lang.String'强制转换为类 'org.gradle.api.file.FileCollection'

android - 服务可以接收自己的广播吗?

android - Exoplayer 2 防止视频播放时屏幕变暗

java - Cobertura-不再检测类(class)

android - getSupportFragmentManager() 导致 java.lang.IllegalStateException : Can not perform this action after onSaveInstanceState